FAQ
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.
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/a13ae0e4-ca48-4908-869c-d22589361032%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Sergiy Khohlov at Oct 21, 2013 at 5:45 am
    Task is really simple :
    Take a look at https://docs.djangoproject.com/en/dev/topics/auth/default/
      (this a good start for novice)
      Use UserCreationForm for passing data from user and validating
    If form is correct save new user
    After this you can redirect to new page
    Many thanks,

    Serge


    +380 636150445
    skype: skhohlov

    On Mon, Oct 21, 2013 at 3:24 AM, 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.
    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/a13ae0e4-ca48-4908-869c-d22589361032%40googlegroups.com.
    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 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/CADTRxJMmoModeqrbLb4Uzf%2BJ7OjZh6Zxyc-Hq-az54gM0xqgCA%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Daniel Roseman at Oct 21, 2013 at 9:55 am

    On Monday, 21 October 2013 01:24:22 UTC+1, 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

    This is indeed a very simple request. And it is fully covered in the
    documentation about forms:
    see https://docs.djangoproject.com/en/1.5/topics/forms/ for an
    introduction,
    and https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/ for the
    specifics about saving form data to a model instance.

    (The other answer to this question, from Sergiy, seems to have completely
    missed the point with his link to the auth docs, unfortunately.)
    --
    DR.

    --
    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/1d9a7cea-b991-42be-84d4-bf13f74eeaa3%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ideo Rex at Oct 22, 2013 at 1:36 am
    Thanks for the link. I'm spent a good part of the day trying to figure it
    out to no avail. My next approach was to describe how I walked through it
    and see where I went wrong.

    I went into my models.py

    from django.db import models

    from django.core.urlresolvers import reverse

    from datetime import *

    from django.forms import ModelForm


    # Create your models here.


    class Ride(models.Model):

         title = models.CharField(max_length=255)

         speed = models.CharField(max_length=255)

         discipline = models.CharField(max_length=255)

         slug = models.SlugField(unique=True, max_length=255)

         description = models.CharField(max_length=255)

         scheduletime = models.DateTimeField('date published')

         lat = models.FloatField(blank=True, null=True)

         lon = models.FloatField(blank=True, null=True)

         published = models.BooleanField(default=True)

         created = models.DateTimeField(auto_now_add=True)






         class Meta:

             ordering = ['-created']



         def __unicode__(self):

             return u'%s' % self.title



         def get_absolute_url(self):

             return reverse('blog.views.post', args=[self.slug])


    class RideForm(ModelForm):

         class Meta:

             model = Ride

             fields = ('title', 'speed', 'discipline', 'description',
    'scheduletime', 'lat', 'lon')


    I became really confused after this point. It is unclear to me how I cause
    a html site to produce a request and for it to make its way to this model.



    *Approach #2*

    I tried to solve this another way. I looked at the polls-tutorial which I
    have done before. I tried to replicate their vote function in views.py. The
    challenge that I found was that I struggled to make a unique object on the
    response of the program. Does anyone have any tips for making this happen.
    Thanks
    On Monday, October 21, 2013 2:55:33 AM UTC-7, Daniel Roseman wrote:
    On Monday, 21 October 2013 01:24:22 UTC+1, 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

    This is indeed a very simple request. And it is fully covered in the
    documentation about forms: see
    https://docs.djangoproject.com/en/1.5/topics/forms/ for an introduction,
    and https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/ for
    the specifics about saving form data to a model instance.

    (The other answer to this question, from Sergiy, seems to have completely
    missed the point with his link to the auth docs, unfortunately.)
    --
    DR.
    --
    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/3110176c-ce5f-4b6e-bb78-b456423a78b6%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Pitchblack at Sep 16, 2014 at 4:02 am
    Is there a way to add the user to the data model, so it knows who created
    the record and who updated it last?
    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.
    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/e5e91694-3637-4fd9-8c3e-0edb4606477e%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Mike Dewhirst at Sep 16, 2014 at 1:58 pm

    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


    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
    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/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>.
    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/541841E5.3010703%40dewhirst.com.au.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Martin at Sep 16, 2014 at 5:22 pm
    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>



    On Tue, Sep 16, 2014 at 6:57 AM, Mike Dewhirst 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

    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
    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/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>.
    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/541841E5.3010703%40dewhirst.com.au.

    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/CAD0urK1J4L4ovc8oh5bUJ_xKhF9a-oe1YgtPoJOOJLm2R4h68A%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Mike Dewhirst at Sep 16, 2014 at 10:44 pm

    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 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
    To post to this group, send email to
    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
    To post to this group, send email to 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+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/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+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/5418BD28.5000103%40dewhirst.com.au.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedOct 21, '13 at 12:24a
activeSep 16, '14 at 10:44p
posts8
users5
websitedjangoproject.com

People

Translate

site design / logo © 2022 Grokbase