This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('.add-book').click(function(ev){ | |
| ev.preventDefault(); | |
| var count = $('.books').children().length; | |
| var tmplMarkup = $('#book-template').html(); | |
| var compiledTmpl = _.template(tmplMarkup, { id : count }); | |
| $('div.books').append(compiledTmpl); | |
| // update form count | |
| $('#id_books-TOTAL_FORMS').attr('value', count+1); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/html" id="book-template"> | |
| <div id="book-<%= id %>"> | |
| <label for="id_books-<%= id %>-title">Book Title:</label> | |
| <input id="id_books-<%= id %>-title" type="text" name="books-<%= id %>-title" maxlength="100"> | |
| <input type="hidden" name="books-<%= id %>-author" id="id_books-<%= id %>-author"> | |
| <input type="hidden" name="books-<%= id %>-id" id="id_books-<%= id %>-id"> | |
| </div> | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.views.generic import CreateView | |
| from django.shortcuts import redirect | |
| from .models import Author | |
| from .forms import AuthorForm, BookFormSet | |
| class AddAuthorView(CreateView): | |
| template_name = 'create_author.html' | |
| form_class = AuthorForm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import forms | |
| from django.forms.models import inlineformset_factory | |
| from .models import Author, Book | |
| class AuthorForm(forms.ModelForm): | |
| class Meta: | |
| model = Author | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| class Author(models.Model): | |
| name = models.CharField(max_length=100) | |
| class Book(models.Model): | |
| author = models.ForeignKey(Author) | |
| title = models.CharField(max_length=100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PersonBase(models.Model): | |
| name = models.Charfield() | |
| address = models.Charfield() | |
| class Meta: | |
| abstract = True | |
| class Employee(PersonBase): | |
| emp_id = models.CharField() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A guy walks into a bar and orders a shot of whisky. He gulps it down and peeks into his shirt pocket. | |
| He then orders another shot of whisky, gulps it down and peeks into his short pocket. | |
| He orders a third shot and does the same thing. After the sixth shot, he asks the bartender for the bill, pays and starts to walk out. | |
| Curiosity gets the better of the bartender and he says to the guy: | |
| "Excuse me, but I noticed that every time you drank a shot, you kept looking into your pocket. I was wondering what's in your pocket. | |
| "The guy slurs, "Well, I have a picture of my wife in my pocket. I keep drinking until she starts to look good." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [program:program_name1] | |
| environment = PYTHONPATH="<< set up your python path here >>",DJANGO_SETTINGS_MODULE="program.settings" | |
| command=<< path to project >>/manage.py celeryd -v 2 -B -s celery -E -l INFO | |
| user=nobody | |
| numprocs=1 | |
| stdout_logfile=/var/log/celery/program_name1.log | |
| stderr_logfile=/var/log/celery/program_name1.err | |
| autostart=true | |
| autorestart=true |