Form in Django Admin for "notes" or "comments" on models -


basically want way have admins leave comments on model being viewed. let's have model car have registered within admin site , want allow other admins write short note car , have show in admin interface along name , timestamp.

essentially want add commenting form in django admin specific model.

any suggestions on how without overriding entire view?

round 2 (edit)

this progress using gordonsbeards answer.

how admin looks now

it adding 3 "extra" empty notes not deal breaker interesting none less.

# in models.py class note(models.model):     user = models.foreignkey(user)     note = models.textfield()     created_on = models.datetimefield(auto_now_add=true)      def __unicode__(self):         return "created on: {}".format(self.created_on) 

my user model handles both admin users , want add notes functionality on. how add logged in users name in front of created on date?

i don't know mean "overriding entire view", because kind of thing makes django nifty use, ability bolt on functionality without fuss. assuming i'm not put entire foot mouth, how approach it:

adding notes shouldn't overly difficult, define model within cars.models , add notes. have model reference cars model it's foreign key , zippozappo - you've got notes.

as "restricting" admin, unless public views let people add notes or display notes, shouldn't ever appear outside of admin application.

site/models.py

from django.contrib.auth.models import user # snip stuff... class notes(models.model)     user = models.foreignkey('auth.user')     author = models.foreinkey('auth.user')     note = models.textfield()     created_on = models.datetimefield(auto_now_add=true) 

make sure ./manage syncdb after this!

site/admin.py

from site.models import notes django.contrib.auth.models import user  class notesinline(admin.stackedinline):     model = notes     = 0  class useradmin(useradmin):     inlines = [notesinline,]  admin.site.unregister(user) admin.site.register(user, useradmin) 

here notes using inline admin stuff, in case wanted customize display of notes @ end of each car: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.modeladmin.inlines

of course can expand/change/alter how like, shouldn't have tricky add additional functionality models.

ideally you'd create notes app, let comment on whatever object wish, not users.

edit

class notesinline has extra=0. stop 3 records showing default on user page.

class notes has author = models.foreinkey('auth.user') on it, need keep track of left note in first place. add dropdown box let select leaving note. if i'm understanding correctly, you'd have field auto-filled out logged-in user. problem forcing while on admin panel, admins created equally (unless limited permissions), limit author field logged-in user require more tinkering should bother with.

if need extend admin panel point you'd auto-fill out these fields, have create other public view, , restrict access users have permissions access it. either or have start overriding admin views/templates yourself. kind of by-design feature of django's admin panel - should used modifying tables, not being end-all user-input panel.

one more headache: django's syncdb not alter tables exist, if want add/remove column existing model, need drop , recreate table, or use django-evolution. use of question however.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -