Inlineformset without foreign key possible?

117 views
Skip to first unread message

Layne Sadler

unread,
Jun 5, 2018, 5:04:17 PM6/5/18
to Django users

I'm trying to implement an inline formset for two models in a graph database. The problem that I'm running into is that formsets are designed with foreign keys in mind.


I'm relating a model to itself through another model. For simplicity sake, let's call them a Person model and a FriendRel model:

Person -[FRIENDS_WITH]-> Person

FriendRelFormSet = inlineformset_factory(Person, FriendRel, form=FriendRelForm, extra=1)


I've tried setting the fk_name=None argument, but I am still met with the following error:


ValueError: 'django_rel.RelationshipMeta' has no ForeignKey to 'django_node.NodeMeta'.


So now I am looking into the documentation below, but it is a bit abstract for my skillset. Am I banging my head against the wall with this, or is it possible to avoid the whole foreign key thing?

Overriding methods on an InlineFormSet   https://docs.djangoproject.com/en/2.0/topics/forms/modelforms/#overriding-methods-on-an-inlineformset

Matthew Pava

unread,
Jun 5, 2018, 5:08:35 PM6/5/18
to django...@googlegroups.com

I’m not able to wrap my head around your specific application, but if you don’t want to use a ForeignKey on a formset, don’t use an InlineFormset.

Just use a regular BaseFormset.

https://docs.djangoproject.com/en/2.0/topics/forms/formsets/

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dcbe2177-6593-4b6d-b0a6-6a9af3813f19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

HashRocketSyntax

unread,
Jun 5, 2018, 5:12:27 PM6/5/18
to Django users
Thank you for pointing me in the right direction =) looks like that class is more generic. 
Reply all
Reply to author
Forward
0 new messages