1

Experimenting with django, I am trying to design a site that will reference registered users of the site as well as non-registered users. Trying to figure out how to best design my models for this, I'd like to give the non-registered user the ability to register and have it linked to the information I already have. I've read some other SO questions that are sort of related so I know I should be using a seperate class (registered & non-registered), but how would I reference 2 different models using a one foreign key?

Models.py:

from django.db import models
from django.contrib.auth.models import User

class NonRegisteredPerson(models.Model):
    first_name = models.CharField(max_length=20, default='')
    last_name = models.CharField(max_length=20, default='')
    email = models.EmailField(max_length=20,default='', blank=True)

class Seat(models.Model):
    num = models.CharField(max_length=100, blank=True) 
    # For the Non Registered User
    occupant = models.ForeignKey('NonRegisteredPerson')
    # For the Registered User - using Built-in User
    occupant = models.ForeignKey(User)

How do I get "occupant" to reference NonRegisteredPerson and User?

Don't know if this matters, but the way I would handle if a NonRegisteredUser signs up for the site, is check if their e-mail exists in the NonRegisteredPerson model, if it does then delete them from that model and add to the Built-in User.

I know this must be a common scenario, but I don't know what or where I should be looking up for this. TIA.

user1347648
  • 65
  • 2
  • 12
  • 1
    What question suggested you use two different classes? It seems to me that you would want a single class, or worst case, inheritance where the registered user is a subclass of the unregistered user. – Pace Jun 07 '13 at 14:32
  • http://stackoverflow.com/questions/13429793/django-how-to-have-models-for-registered-site-users-and-non-site-users – user1347648 Jun 07 '13 at 17:33
  • Can you give me an example of how to use this in a single class or where i can read more about it? – user1347648 Jun 07 '13 at 17:35

0 Answers0