hi all,
i use inlineformset_facotry to edit & save the additional values for
my model.
#model.py
class ListingShippingService(models.Model):
site = models.ForeignKey(Site)
is_international = models.BooleanField(default=False)
is_flat = models.BooleanField(default=False)
is_calculated = models.BooleanField(default=False)
service = models.CharField(max_length=255)
description = models.TextField()
class ListingShippingDomestic(models.Model):
listing = models.ForeignKey(Listing)
service = models.ForeignKey(ListingShippingService)
cost = models.CharField(max_length=255, help_text='("Input 0
for free shipping")')
additional_cost = models.CharField(max_length=255, blank=True,
null=True)
is_free = models.BooleanField(default=False)
class ListingShippingInternational(models.Model):
listing = models.ForeignKey(Listing)
service = models.ForeignKey(ListingShippingService)
cost = models.CharField(max_length=255)
additional_cost = models.CharField(max_length=255, blank=True,
null=True)
ship_to_locations =
models.ManyToManyField(ListingInternationalShippingArea)
#forms.py
class ListingShippingInternationalForm(forms.ModelForm):
def __init__(self, * args, ** kwargs):
site_id = kwargs.get('site_id',None)
del kwargs['site_id']
super(ListingShippingInternationalForm, self).__init__(*args,
** kwargs)
service =
models.ListingShippingService.objects.filter(site=site_id,
is_international=True)
self.fields['service'].queryset = service
self.fields['ship_to_locations'].queryset =
models.ListingInternationalShippingArea.objects.filter(site=site_id)
class Meta:
exclude = ('listing',)
model = models.ListingShippingInternational
#views.py
from django.forms.models import inlineformset_factory
import models,forms
internationalInlineFormSet = inlineformset_factory(models.Listing,
models.ListingShippingInternational, max_num=3,
form=forms.ListingShippingInternationalForm(site_id='xx'))
### here is my problem the works is:
internationalInlineFormSet = inlineformset_factory(models.Listing,
models.ListingShippingInternational, max_num=3,
form=forms.ListingShippingInternationalForm)
### once i put (site_id='xx'), it will not work, how can i
passing the parameter to it for create dynamic form?
can anybody helps? Thx!
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.