-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a form that adds a content_object
- Loading branch information
Felipe Álvarez
committed
Aug 22, 2017
1 parent
c4a29e1
commit f608eaf
Showing
4 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.forms import ModelForm | ||
from agenda.models import Activity | ||
|
||
|
||
class ActivityForm(ModelForm): | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.content_object = kwargs.pop('content_object', None) | ||
super(ActivityForm, self).__init__(*args, **kwargs) | ||
|
||
def save(self, commit=True): | ||
activity = super(ActivityForm, self).save(commit=commit) | ||
if commit: | ||
activity.content_object = self.content_object | ||
activity.save() | ||
return activity | ||
class Meta: | ||
model = Activity | ||
fields = ['date', 'url', 'description', 'location'] |
This file contains 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
This file contains 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
This file contains 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