Django model with FK to learner app model Group is displaying options from user admin Group
I have the following models:
learner app
class Group(models.Model):
short_name = models.CharField(max_length=50) # company acronym
slug = models.SlugField(default="prepopulated_do_not_enter_text")
contract = models.ForeignKey(Contract, on_delete=models.CASCADE)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
start_date = models.DateField()
end_date = models.DateField()
notes = models.TextField(blank=True, null=True)
class Meta:
ordering = ["short_name"]
unique_together = (
"short_name",
"contract",
)
management app I've set up an Invoice model:
from django.db import models
from learner.models import Group
class Invoice(models.Model):
staff = models.ForeignKey(Staff, on_delete=models.RESTRICT)
group = models.ForeignKey(Group, on_delete=models.RESTRICT)
date = models.DateField()
amount = models.DecimalField(max_digits=7, decimal_places=2)
note = models.CharField(max_length=500, null=True, blank=True)
When I try to add an invoice instead of the learner groups I'm being offered the user admin Group options:
Can anyone help with what I'm doing wrong. I have the learner group as a FK in other models without issue.
In your learner.models you probably somewhere import the Group of the django.contrib.auth.models module:
# learner/models.py
# ...
class Group(models.Model):
# ...
from django.contrib.auth.models import Group
# use of Group
your pobably better rename the import of the second one, and rename all occurrences of that:
# learner/models.py
# ...
class Group(models.Model):
# ...
from django.contrib.auth.models import Group as AuthGroup
# use of AuthGroup (find-replace)
this will also require migrating the database.
