Wednesday, July 16, 2014

Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

Thanks, I eventually solved it by using django to generate the models i believe it was because i was defining the db_column in the primary key and django said whatever, so when inspectdb built the models file it took that out and it started to work.

On Wednesday, July 16, 2014 12:28:27 PM UTC-6, Frank Bieniek wrote:
Hi there,
you are telling django, you know what you are doing via

managed = False -> no batteries included, please read the details here
https://docs.djangoproject.com/en/dev/ref/models/options/

There are great books out there explaining django from
other perspectives than the online documentation

Two Scoops of Django
http://www.amazon.com/Two-Scoops-Django-Best-Practices/dp/098146730X/

Test driven development in python
http://www.amazon.com/Test-Driven-Development-Python-Harry-Percival/dp/1449364829/

Hope this helps
Frank



Am 16.07.14 19:08, schrieb G Z:
so I added a db trigger in oracle and it still said the same thing when ever I tried to save the new addition. Also whenever I try to go to an existing vm the manytomany field throws an exception that table or view doesn't exist but when I goto add new it doesnt and the correct field is displayed, but then when i save it says can't be null.


What changes from what you can see could I make to curb these problems?



class License(models.Model):
   license_id = models.AutoField(primary_key = True, editable = False, db_column='license_id')
   license_authority_id = models.ForeignKey(License_authoritie,  on_delete = models.PROTECT, db_column='license_authority_id')
   product = models.CharField(max_length = 20)

   class Meta:
      managed = False
      db_table = 'licenses'
      ordering = ['product']

   def __unicode__(self):  # Python 3: def __str__(self):
      return self.product
        
class Vm_license(models.Model):
   vm_license_id = models.AutoField(primary_key = True, db_column='vm_license_id')
   vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, db_column='vm_id')
   license = models.ManyToManyField(
License)


   class Meta:
      managed = False
      db_table = 'vm_licenses'


class vm_license_admin(admin.ModelAdmin):
    #list_display = ('vm_id', 'license_id')
    list_display = ('vm_id',)
    search_fields = ('vm_id__vm_name',)
    ordering = ('vm_id',)
    filter_horizontal = ('license',)
   
admin.site.register(Vm_license, vm_license_admin)
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9ecf5d7f-c303-4742-9ad7-a1a56bddb716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f43f1646-be81-457a-bb0f-38ffa918ddcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment