For some reasons (particularly, to try making DB scheme upgrading easier), I need to store all the user’s extended properties in another object (like in this question to separate Person and Address)
I have an AUTH_PROFILE_MODULE override set and do capture def_user_profile.
class CustomUser(models.Model):
user = models.ForeignKey(User, unique=True)
def create_user_profile(sender, instance, created, **kwargs):
if created:
CustomUser.objects.create(user=instance)
The question is: if I add a custom type property to CustomUser, like this:
class CustomPropertySet(models.Model):
this_is_a_Farmer = models.BooleanField()
class CustomUser(models.Model):
user = models.ForeignKey(User, unique=True)
extdata = models.CustomProperySet()
Will this automatically create a CustomProperySet entry at adding new user? Does CustomPropertySet needs to be associated back with ForeignKey to its CustomUser owner?
Second question: how to delete extended properties like this when object is deleted?
The obvious answer to these is “try it and find out”, but we’re a polite people here…
When you assign something to
extdatawhat do you assign? Assigning True and False probably won’t work, you’d have to assign a CustomPropertySet instance, and to get one you’ll have to create one.Try it and this will become clear.
No. The CustomProper t ySet can survive all on it’s lonesome. Your CustomUser points to it, but it’s not bashful and doesn’t care who or how many people point at it.
See the documentation about cascading deletes