I have one app with a class Navbar in models.py:
class Navbar(models.Model):
node = models.ForeignKey(Node, ...)
nav_link = models.ForeignKey(NavLink, ...)
and a class NavLink:
class NavLink(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField()
I have a second app with a class Intro in models.py:
class Intro(models.Model):
node = models.ForeignKey(Node, ...)
nav_link = models.ForeignKey(NavLink, ...)
In forms.py of the second app I have the following form:
from headers.models import Navbar, NavLink
class IntroForm(ModelForm):
nav_link = ModelChoiceField(queryset=None, empty_label='Intro')
class Meta:
model = models.Intro
fields = (
'nav_link',
...,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
qs1 = Navbar.objects.filter(node_id=user.node_id)
qs2 = models.Intro.objects.filter(node_id=user.node_id)
qs1.difference(qs2)
self.fields['nav_link'].queryset = NavLink.objects.filter(id__in=???)
What I want is the ModelChoiceField to contain only the choices that user.node_id
hasn’t chosen yet.
The first issue is that name 'user' is not defined
. Is there a way to get access to user.node_id
in forms.py or should this code go elsewhere?
The second issue is that for id__in=
I need a list with the nav_link ids, how do I make a list out of qs1?
Kind regards,
Johanna