HI
I get the error when i enter the records of Profile Model and save it. i get GUI for model.
I created group and given access of both model to dgp user.
ValueError at /admin/newapp/profile1/
dgp is my user name and Employee is the model name.
Can anybody help me in this regards
Employee Refers to User Model ( Foreign Key Relation)
Profile Model Refers to Employee Model ( Foreign Key Relation)
Models.py
class Employee(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE,primary_key="True")
department = models.CharField(max_length=100)
level = models.IntegerField()
parentlevel = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return '%s' % (self.user)
class Profile(models.Model):
State = models.CharField(max_length=100,default="MH")
District = models.CharField(max_length=100,default="Parbhani")
user = models.ForeignKey(Employee, on_delete=models.CASCADE)
InwardNumber = models.CharField(max_length=100,default="2019/3")
admin.py
class Profile1Admin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
username = request.user.username
print("----- Inside get_exclude Method--------")
print (username)
if username == 'dgp': # if user is not a superuser
def get_form(self, request, obj=None, **kwargs):
username = request.user.username
print("----- Inside get_exclude Method--------")
print (username)
if username == 'dgp': # if user is not a superuser
LOGIC 1 --------
elif username == 'inumber':
LOGIC 2 ----
print("----- *********** Inside DGP LOGIN ***-------")
self.fields = self.inward_fields
else:
self.fields = self.inward_fields
else:
Logic 3 --
return super(Profile1Admin, self).get_form(request, obj, **kwargs)
Can Anyone please help me in this regards.
--
Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,
Asst. Professor
Department of Information Technology,
SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India
Official: bsshetty@sggs.ac.in
Mobile: +91-9270696267
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAECSbOvG66UTQFMZHemVrfJY0zdoteyfFQ3NK6_6vxqAgy2OyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment