python - Django Admin: Add foreign keys at same time as model -
i novice in django , i'm learning ropes of admin interface. have model several foreign keys. these foreign keys reference other foreign keys. on admin website after register property model , try add given dropdown box each foreign key model. dropdown box lists existing foreign keys. (http://i.stack.imgur.com/e5lcu.png)
what great if instead of dropdown box there fields add foreign key models add property model. way wouldn't have manually add foreign keys , go , add more, , go , add property data.
how can this? feels simple enough question after intense googling still can't find answer, apologize in advance.
example of 2 of models:
class address(models.model): state = models.foreignkey('state') address1 = models.charfield(max_length=200) address2 = models.charfield(max_length=200) city = models.charfield(max_length=200) postal_code = models.charfield(max_length=200) class property(models.model): address = models.foreignkey('address', blank=true, null=true) borrower = models.foreignkey('person', blank=true, null=true) company = models.foreignkey('company', blank=true, null=true) contract = models.foreignkey('contract', blank=true, null=true) loan_balance = models.integerfield() name = models.charfield(max_length=200) primary_email = models.charfield(max_length=200) primary_phone = models.charfield(max_length=200) property_no = models.integerfield()
example of admin.py:
# register models here. class propertyadmin(admin.stackedinline): model = property class personadmin(admin.stackedinline): model = person class companyadmin(admin.stackedinline): model = company class contractadmin(admin.stackedinline): model = contract class completepropertyadmin(admin.modeladmin): inlines = [propertyadmin, personadmin, companyadmin, contractadmin] admin.site.register(property)
one solution problem can be, create custom form fields both models , @ time of saving values, first create instance of address model , instance save final property model.
Comments
Post a Comment