Django - Usecases for Formset and Inline Formset? -
i'm in doubt 1 use(formset or inline formset).
i've on-line delivery request form reserve bicycles. there more 1 type of bicycles , because of i've 2 models "deliveryrequests" , "deliveryrequestbikes".
class deliveryrequests(models.model): pickup_date = models.datefield() return_date = models.datefield() pickup_hour = models.timefield() return_hour = models.timefield() name = models.charfield(max_length=100, null=false, blank=false) email = models.emailfield(null=false, blank=false) phone = models.charfield(max_length=25, null=false, blank=false) location_name = models.charfield(max_length=100, null=false, blank=false) address_to_delivery = models.charfield(max_length=200, null=false, blank=false) message = models.textfield(null=true, blank=true) deliveryrequeststatus = models.foreignkey(deliveryrequeststatus, null=false, blank=false) comment = models.textfield(null=true, blank=true) date_insert = models.datetimefield(auto_now_add=true) date_last_modification = models.datetimefield(auto_now=true) def __unicode__(self): return self.name class meta: # order in admin name of section ordering = ['-id'] class deliveryrequestbikes(models.model): deliveryrequest = models.foreignkey(deliveryrequests, null=false, blank=false) biketype = models.foreignkey(biketypes, null=false, blank=false) units = models.integerfield(null=false, blank=false) date_insert = models.datetimefield(auto_now_add=true) date_last_modification = models.datetimefield(auto_now=true) def __unicode__(self): return self.deliveryrequest class meta: # order in admin name of section ordering = ['biketype']
i forgot explicitly front end form. need able insert one "deliveryrequests" register one or more "deliveryrequestbikes"
which 1 should use, formset or inline formset?
please give advice.
best regards,
inline formsets small abstraction layer on top of model formsets. these simplify case of working related objects via foreign key.
it seems inline formsets want. optionally can specify how many deliveryrequestbikes
want allow deliveryrequests
.
give them try with:
from django.forms.models import inlineformset_factory deliveryrequestbikesformset = inlineformset_factory(deliveryrequests, deliveryrequestbikes, fk_name="deliveryrequest")
Comments
Post a Comment