On Mon, Mar 4, 2013 at 10:31 PM, Marc Aymerich <[email protected]> wrote:
> 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 ?
>
Sure - just provide the initial data as actual data. If, instead of using
'initial', you pass the same content as 'data', the form will be saveable.
Yours,
Russ Magee %-)
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.