0

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:

enter image description here

Can anyone help with what I'm doing wrong. I have the learner group as a FK in other models without issue.

asked Sep 16 at 8:43
2
  • Do you by any chance import the django.contrib.auth.models.Group in the learner.models module? Commented Sep 16 at 9:36
  • Yes, I do. If that's the issue, any thoughts on how I can differentiate between the two? Commented Sep 16 at 9:44

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!! That makes sense - I appreciate you taking the time to help out.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.