class UserSIMS(models.Model):
TATA_USAHA = 0
DOSEN = 1
MAHASISWA = 2
TYPE_CHOICES = ((TATA_USAHA, 'Tata Usaha'), (DOSEN, 'Dosen'), (MAHASISWA, 'Mahasiswa'))
user = models.OneToOneField(User)
type = models.IntegerField(choices=TYPE_CHOICES) # 0 = TU 1 = dosen 2 = mahasiswa
class Group(models.Model):
name = models.CharField(max_length=100)
lecturer = models.ForeignKey(User, null=True, blank=True, limit_choices_to={'usersims': UserSIMS.DOSEN})
company = models.ForeignKey(Company, null=True, blank=True)
tor = models.FileField(upload_to='tor', null=True, blank=True)
logact = models.FileField(upload_to='logact', null=True, blank=True)
document = models.FileField(upload_to='document', null=True, blank=True)
created_at = models.DateTimeField(null=True, blank=True)
updated_at = models.DateTimeField(null=True, blank=True)
def save(self, *args, **kwargs):
if not self.id:
self.created_at = datetime.datetime.today()
self.updated_at = datetime.datetime.today()
super(Group, self).save(*args, **kwargs)
And this is my group admin model
class GroupAdmin(admin.ModelAdmin):
list_display = ("name", "lecturer", "company")
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "lecturer":
kwargs["queryset"] = User.objects.filter(usersims__type=UserSIMS.DOSEN)
return super(GroupAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
admin.site.register(Group, GroupAdmin)
What should I do? Thanks in advance. :D
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:
Post a Comment