On Sun, Jan 27, 2013 at 10:40 PM, Edwin Lunando <edwinlunando@gmail.com> wrote:
Here is my model:class UserSIMS(models.Model):TATA_USAHA = 0DOSEN = 1MAHASISWA = 2TYPE_CHOICES = ((TATA_USAHA, 'Tata Usaha'), (DOSEN, 'Dosen'), (MAHASISWA, 'Mahasiswa'))user = models.OneToOneField(User)type = models.IntegerField(choices=TYPE_CHOICES) # 0 = TU 1 = dosen 2 = mahasiswaclass 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 modelclass 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)When i tried to update the group or add a new group, there are error like this "Model user with pk 1L does not exist".--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.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@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