Re: How to create model for this json data

2019-02-20 Thread 'Amitesh Sahay' via Django users
Hi,
First, try to understand the error messages. It says there are fields that are 
required, but you are leaving them blank. Then, there are some fields those 
cannot have "null", but soemhow you are adding null values to them.
I would suggest using below Django CLI commands to add the data to your table
python manage.py loaddata .
Below is the link that will guide you with further informationDjango dumpdata 
and loaddata (Example)


| 
| 
| 
|  |  |

 |

 |
| 
|  | 
Django dumpdata and loaddata (Example)

A protip by itseranga about django, database, model, and dumpdata.
 |

 |

 |


I hope that will come handy to you.
Regards,
Amitesh Sahay91-750 797 8619 

On Wednesday, 20 February, 2019, 12:31:23 pm IST,  
wrote:  
 
 

On Tuesday, February 19, 2019 at 10:02:32 PM UTC+5:30, optvi...@gmail.com wrote:
Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

i define a class with foreign key but still getting error?

class keywordfield(models.Model):
keyword=models.CharField(max_length=50,null=True)
appNamefield=models.ForeignKey("appNamefield", on_delete=models.CASCADE)






class appNamefield(models.Model):
appName = models.CharField(max_length=50,null=True)


serializer class
class appDetailsSearilizer(serializers.ModelSerializer):
class Meta:
model = keywordfield


fields = ('id','keyword','appNamefield')

json data

{
  
"keyword": "food",
  "appNamefield":["j","l"]

  
}


error
dict_items([('required', 'This field is required.'), ('null', 'This field may 
not be null.'), ('invalid', 'Invalid data. Expected a dictionary, but got 
{datatype}.')])
 



 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/914062e6-1475-4653-8010-58a43b5bacb6%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+unsubscr...@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/1172024440.2200567.1550650685702%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create model for this json data

2019-02-19 Thread optvisitor


On Tuesday, February 19, 2019 at 10:02:32 PM UTC+5:30, optvi...@gmail.com 
wrote:
>
> Hi I have data like this 
> { 
> "Name" : "pk", 
> "Applist" : ["zom","bc"], 
>  "Url":   ["As","de"] 
>
> } 
>
> How to define field name for list I am not getting


i define a class with foreign key but still getting error?

class keywordfield(models.Model):
keyword=models.CharField(max_length=50,null=True)
appNamefield=models.ForeignKey("appNamefield", on_delete=models.CASCADE)






class appNamefield(models.Model):
appName = models.CharField(max_length=50,null=True)


serializer class
class appDetailsSearilizer(serializers.ModelSerializer):
class Meta:
model = keywordfield


fields = ('id','keyword','appNamefield')

json data

{
  
"keyword": "food",
  "appNamefield":["j","l"]

  
}


error
dict_items([('required', 'This field is required.'), ('null', 'This field may 
not be null.'), ('invalid', 'Invalid data. Expected a dictionary, but got 
{datatype}.')])

 




 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/914062e6-1475-4653-8010-58a43b5bacb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: How to create model for this json data

2019-02-19 Thread Matthew Pava
You can use ForeignKey.
Or ArrayField if you're using PostgreSQL as your backend.

https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#arrayfield


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of optvisi...@gmail.com
Sent: Tuesday, February 19, 2019 10:02 AM
To: Django users
Subject: How to create model for this json data

Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1dbdd1f4-6d19-4cc7-828b-e360395edf6e%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+unsubscr...@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/b5f32b6b7e4643d19fdb30c83b8bb229%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


How to create model for this json data

2019-02-19 Thread optvisitor
Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1dbdd1f4-6d19-4cc7-828b-e360395edf6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.