Saturday, September 30, 2017

Add value to database without using forms in django

I have a model named "Name" which stores the list of all cities present in other model named  "City". How can it be done internally in the views.py without using forms. Here is the code of models.py

"
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


class Detail(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)

    def __str__(self):
        return str(self.username)


class City(models.Model):
    userName = models.ForeignKey(Detail, blank=True, null=True)
    city1 = models.CharField(max_length=100)
    city2 = models.CharField(max_length=100)
    city3 = models.CharField(max_length=100)
    city4 = models.CharField(max_length=100)
    city5 = models.CharField(max_length=100)
    def __str__(self):
        return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)

class Name(models.Model):
    cityval=models.CharField(max_length=100)
"

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment