Monday, March 4, 2013

Django inline formsets, force initial data to be saved.

Hi,
I've spend several hours trying to figure out how to save inlines with initial data in them.

basically I have a very simple model with 2 fields:

class DirectIface(models.Model):
    parent = models.ForeignKey('nodes.Node')
    name = models.CharField(max_lenght=64)

And what I'm doing is defining a formset with initial data in it:

class DirectIfaceInlineFormSet(BaseInlineFormSet):
    def __init__(self, *args, **kwargs):
        kwargs['initial'] = [{ 'name': 'eth1', }, {'name': 'eth2'},]
        super(DirectIfaceInlineFormSet, self).__init__(*args, **kwargs)


In this case 2 Direct ifaces with names eth1 and eth2.

The problem is that those ifaces doesn't get stored when I hit the save button, that's because has_changed == False.
So is there a way to tell Django to save formsets with only initial data ?

Thanks !

--
Marc

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment