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.
1 Answer 1
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.
answered Sep 16 at 9:46
willeM_ Van Onsem
482k33 gold badges483 silver badges624 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Lisa Higgins
Thank you!! That makes sense - I appreciate you taking the time to help out.
default
django.contrib.auth.models.Groupin thelearner.modelsmodule?