I have a django auth user proxy model that has some extra permissions attached to it like so:
class User(User):
class Meta:
proxy = True
permissions = (
("write_messages","May add new messages to front page"),
("view_maps","Can view the maps section"),
)
Elsewhere in the model I have an object that has User as a foreign key:
class Project(models.Model):
creation_date = models.DateTimeField(auto_now_add=True)
modify_date = models.DateTimeField(auto_now=True)
owner = models.ForeignKey(User)
In one of my views I attempt to create a new project using the current user as the owner
@login_required
def new_project(request):
project = Project.objects.create(owner=request.user)
This, however, returns the error:
Cannot assign "<User: mwetter>": "Project.owner" must be a "User" instance.
I’m assuming that the foreign key owner in the project object is referring to the base class for Django User instead of my proxy class. Is there a way to refer to my proxy user as a foreign key instead?
Why are you calling your proxy class
User, which is guaranteed to lead to confusion between that anddjango.contrib.auth.models.User? Why notUserProxy, orMyUser? Then it could be distinguished whenever you use it.