I am facing this problem again n again.
lemme explain you i am working on a complaint management site for my college, I have designed a separate customized admin panel which is working good, but the problem is occurring in making another admin panel for worker, where they can see allotted complaints and other things related to that, but I am not getting my desired result.
ValueError at /worker-login/
The following fields do not exist in this model, are m2m fields, or are non-concrete fields: last_login
**models.py
def generate_id():
alphanumeric = string.ascii_uppercase + string.digits
return ''.join(random.choices(alphanumeric, k=4))
class Assign(models.Model):
id = models.CharField(max_length=4, primary_key=True, unique=True, default=generate_id)
name = models.CharField(max_length=20)
email = models.EmailField(max_length=30, unique=True)
dob = models.DateField(null=True, blank=True)
department = models.ForeignKey('Department', on_delete=models.SET_NULL, null=True, blank=True)
phone_number = models.CharField(max_length=13, unique=True)
profile_picture = models.ImageField(upload_to='profile_pictures/', blank=True, null=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['dob']
class Meta:
# Add this to prevent clashes with auth.User's groups and user_permissions
default_related_name = 'assign_users'
def save(self, *args, **kwargs):
if not self.id:
self.id = generate_id()
super().save(*args, **kwargs)
def __str__(self):
return self.email
**views.py
def worker_login(request):
if request.method == 'POST':
email = request.POST.get('email')
id = request.POST.get('id')
user = authenticate(request, email=email, id=id)
if user is not None:
login(request, user, backend='app1.authentication_backends.AssignBackend')
return redirect('worker_dashboard')
else:
messages.error(request, 'Invalid credentials. Please try again.')
return render(request, 'worker_login.html')
@login_required
def worker_dashboard(request):
user = request.user
try:
worker = Assign.objects.get(email=user.email)
except Assign.DoesNotExist:
worker = None
context = {
'worker': worker
}
return render(request, 'worker_dashboard.html', context)
**Urls.py
path('worker-login/', views.worker_login, name='worker_login'),
path('worker-dashboard/', views.worker_dashboard, name='worker_dashboard'),
New contributor
Prabal Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.