zsoldosp / django-currentuser

Conveniently store reference to request user on thread/db level.
BSD 3-Clause "New" or "Revised" License
139 stars 40 forks source link

Problem with custom users models #13

Closed AhmedWagdi1 closed 6 years ago

AhmedWagdi1 commented 6 years ago

In my django project am not using the basic user table, I created custom user model,, when I used current user it gives me an error

townoftech_warehouse.Item.created_by: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
    HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

that is how I am using it in models.py

class Item(models.Model):
    item_category = models.ForeignKey(Category, on_delete="PROTECT")
    item_name = models.CharField(max_length=100, null=False)
    item_quantity = models.IntegerField(default=1)
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    created_by = CurrentUserField(settings.AUTH_USER_MODEL)
zsoldosp commented 6 years ago

I guess replacing to='auth.User with to=settings.AUTH_USER_MODEL in in the field's definition would do the trick

any takers? In the foreseeable future I won't have the time to do & test it

kairichard commented 6 years ago

@bui3itf0ky00 there is a new version which fixes the problem. See https://pypi.org/project/django-currentuser/