Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for automatically creating data for django model [closed]

I want to test models which are explained in the Django tutorial. Is there an automatic way to fill them with sample data? It's one of them:

class Book(models.Model):     name = models.CharField(max_length=300)     pages = models.IntegerField()     price = models.DecimalField(max_digits=10, decimal_places=2)     rating = models.FloatField()     authors = models.ManyToManyField(Author)     publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)     pubdate = models.DateField() 

Any suggestion?

like image 278
Joe Avatar asked Apr 12 '11 22:04

Joe


People also ask

What is Django AutoField?

According to documentation, An AutoField is an IntegerField that automatically increments according to available IDs. One usually won't need to use this directly because a primary key field will automatically be added to your model if you don't specify otherwise.

What is Inspectdb in Django?

Django comes with a utility called inspectdb that can create models by introspecting an existing database. You can view the output by running this command: $ python manage.py inspectdb. Save this as a file by using standard Unix output redirection: $ python manage.py inspectdb > models.py.

What is a QuerySet in Django?

A QuerySet is a collection of data from a database. A QuerySet is built up as a list of objects. QuerySets makes it easier to get the data you actually need, by allowing you to filter and order the data.

What is Django CharField?

CharField is a commonly-defined field used as an attribute to reference a text-based database column when defining Model classes with the Django ORM. The Django project has wonderful documentation for CharField and all of the other column fields. Note that CharField is defined within the django.


1 Answers

I haven't used it myself, but django-autofixture looks pretty much like what you are after.

Other similar apps are listed in this grid: https://www.djangopackages.com/grids/g/fixtures/

like image 93
arie Avatar answered Oct 02 '22 13:10

arie