Beispiel #1
0
 def createAuthor(self, **kwargs):
     default = {
         'first_name': 'first_name_test-' + uuid.uuid4().hex,
         'last_name': 'last_name_test-' + uuid.uuid4().hex,
     }
     default.update(kwargs)
     author = Author(**default)
     author.save()
     return author
def populate_author(N=2):
    fake_gen = Faker()
    for i in range(N):
        first_name = fake_gen.first_name()
        last_name = fake_gen.last_name()
        date_of_birth = fake_gen.date_time()
        author = Author(first_name=first_name,
                        last_name=last_name,
                        date_of_birth=date_of_birth)
        author.save()
def authorCreate(request):
    if request.method == 'POST':
        form = AuthorForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            date_of_birth = form.cleaned_data['date_of_birth']
            date_of_death = form.cleaned_data['date_of_death']
            author = Author(first_name=first_name,
                            last_name=last_name,
                            date_of_birth=date_of_birth,
                            date_of_death=date_of_death)
            author.save()
            return redirect('/catalog/authors')
    else:
        form = AuthorForm()

    return render(request, 'catalog/author_form.html', {'form': form})
Beispiel #4
0
# Save the genres to the database
for genre in genres:
    genre.save()

# Create Authors
authors = []
for i in range(1, 10):
    a_fname = fake.first_name()
    a_lname = fake.last_name()
    a_dob = fake.date_of_birth()
    a_dod = a_dob + timedelta(days=365 * fake.random_int(65, 100))
    author = Author(first_name=a_fname,
                    last_name=a_lname,
                    date_of_birth=a_dob,
                    date_of_death=a_dod)
    author.save()
    authors.append(author)

# Create Books
books = []
for i in range(1, 10):
    a_title = fake.text(50)
    a_author = authors[fake.random_int(0, len(authors)) - 1]
    a_summary = fake.text(1000)
    a_isbn = fake.isbn13()
    book = Book(title=a_title, author=a_author, summary=a_summary, isbn=a_isbn)
    book.save()
    book.genre.add(genres[fake.random_int(0, len(genres)) - 1])
    book.save()
    books.append(book)
 def setUpTestData(cls):
     # Set up non-modified objects used by all test methods
     au = Author(first_name='Big', last_name='Bob')
     au.save()