On 17/09/2014 3:22 AM, Michael Martin wrote:
Mike,
Thanks for responding.
I seem to be getting an error when I try to make foreign keys in my
model. Do you have any idea why?
My Model that I am adding is called GeneralSetting
I am now importing:
from django.db import models
from django.contrib.auth.models import User
I added under my
class GeneralSetting(models.Model):
   updated_by=models.ForeignKey(User)
   created_by=models.ForeignKey(User)
   def __unicode__(self):
       return "General Settings"
C:\Users\mike\workspace\ciscoebondinggateway>jython manage.py makemigrations
↠[31;1mCommandError: System check identified some issues:
ERRORS:
↠[31;1msettings.GeneralSetting.created_by: (fields.E304) Reverse
accessor for 'G
eneralSetting.created_by' clashes with reverse accessor for
'GeneralSetting.upda
ted_by'.
       HINT: Add or change a related_name argument to the
definition for 'Gener
alSetting.created_by' or 'GeneralSetting.updated_by'.↠[0m
↠[31;1msettings.GeneralSetting.updated_by: (fields.E304) Reverse
accessor for 'G
eneralSetting.updated_by' clashes with reverse accessor for
'GeneralSetting.crea
ted_by'.
       HINT: Add or change a related_name argument to the
definition for 'Gener
alSetting.updated_by' or 'GeneralSetting.created_by'.↠[0m
↠[0m
C:\Users\mike\workspace\ciscoebondinggateway>
It appears that you need a related_name argument for one or both of
those foreign keys. The Django documentation is probably the best part
of Django. Have a look at https://docs.djangoproject.com/en/1.6/ which
is the entry page. Then in the model layer look under Models and click
the Field types link. When that page comes up scroll down a little to
see Relationship fields in the right-sidebar. The link you want is
Arguments. Alternatively, you could search for related_name but I think
you would be better served as a beginner to start at the entry page and
to follow your nose from there.
Good luck
Mike
On Tue, Sep 16, 2014 at 6:57 AM, Mike Dewhirst <mi...@dewhirst.com.au
<mailto:mi...@dewhirst.com.au>> wrote:
On 16/09/2014 2:02 PM, Pitchblack wrote:
Is there a way to add the user to the data model, so it knows who
created the record and who updated it last?
You need to establish a couple of foreign key fields in your model
(eg created and updated) which both link to auth.user. Then grab
request.user at the appropriate time and do <model>.created =
request.user and <model>.updated = request.user just before saving.
This can be done in the admin
https://docs.djangoproject.__com/en/1.6/ref/contrib/admin/#__django.contrib.admin.__ModelAdmin.save_model
<https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model>
In your own forms it is the same as updating any other fields.
hth
On Sunday, October 20, 2013 5:24:22 PM UTC-7, Ideo Rex wrote:
  Hello,
  I'm relatively new to Django. So I have a working (local) web
  application. I can create new model objects from the admin
site, but
  I would like my users to be able to create their own
objects and
  save them to the database. I'm really confused on the over
arching
  process on how this is down and I would appreciate it if
someone
  could lead me in the correct direction.
  I want to allow my users:
  1. fill in information on a page
  2. submit this page to the database
  3. redirect them to a page that reflects their input ("You
  successfully submitted this {{title}}")
  Thanks
--
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
<mailto:django-users%2bunsubscr...@googlegroups.com>
<mailto:django-users+__unsubscr...@googlegroups.com
<mailto:django-users%2bunsubscr...@googlegroups.com>>.
To post to this group, send email to
django-users@googlegroups.com <mailto:django-users@googlegroups.com>
<mailto:django-users@__googlegroups.com
<mailto:django-users@googlegroups.com>>.
Visit this group at
http://groups.google.com/__group/django-users
<http://groups.google.com/group/django-users>.
To view this discussion on the web visit
https://groups.google.com/d/__msgid/django-users/e5e91694-__3637-4fd9-8c3e-0edb4606477e%__40googlegroups.com
<https://groups.google.com/d/msgid/django-users/e5e91694-3637-4fd9-8c3e-0edb4606477e%40googlegroups.com>
<https://groups.google.com/d/__msgid/django-users/e5e91694-__3637-4fd9-8c3e-0edb4606477e%__40googlegroups.com?utm_medium=__email&utm_source=footer
<https://groups.google.com/d/msgid/django-users/e5e91694-3637-4fd9-8c3e-0edb4606477e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
For more options, visit https://groups.google.com/d/__optout
<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
<mailto:django-users%2bunsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at http://groups.google.com/__group/django-users
<http://groups.google.com/group/django-users>.
To view this discussion on the web visit
https://groups.google.com/d/__msgid/django-users/541841E5.__3010703%40dewhirst.com.au
<https://groups.google.com/d/msgid/django-users/541841E5.3010703%40dewhirst.com.au>.
For more options, visit https://groups.google.com/d/__optout
<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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto: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/CAD0urK1J4L4ovc8oh5bUJ_xKhF9a-oe1YgtPoJOOJLm2R4h68A%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAD0urK1J4L4ovc8oh5bUJ_xKhF9a-oe1YgtPoJOOJLm2R4h68A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
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+unsubscr...@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/5418BD28.5000103%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.