-
Notifications
You must be signed in to change notification settings - Fork 6
/
forms.py
57 lines (38 loc) · 1.58 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django import forms
from django.contrib.contenttypes.models import ContentType
from mimesis.models import Image, ImageAssociation
from mimesis.models import Audio, AudioAssociation
class ImageForm(forms.ModelForm):
class Meta:
model = Image
exclude = ("creator", "created",)
def save(self, request, *args, **kwargs):
self.instance.creator = request.user
super(ImageForm, self).save(*args, **kwargs)
class ImageAssociationForm(forms.ModelForm):
caption = forms.TextField(blank=True)
class Meta:
model = ImageAssociation
fields = ("caption",)
def save(self, request, obj, image, *args, **kwargs):
self.instance.content_type = ContentType.objects.get_for_model(obj)
self.instance.object_pk = obj.pk
self.image = image
super(ImageAssociationForm, self).save(*args, **kwargs)
class AudioForm(forms.ModelForm):
class Meta:
model = Audio
exclude = ("creator", "created",)
def save(self, request, *args, **kwargs):
self.instance.creator = request.user
super(AudioForm, self).save(*args, **kwargs)
class AudioAssociationForm(forms.ModelForm):
caption = forms.TextField()
class Meta:
model = AudioAssociation
fields = ("caption",)
def save(self, request, obj, audio, *args, **kwargs):
self.instance.content_type = ContentType.objects.get_for_model(obj)
self.instance.object_pk = obj.pk
self.audio = audio
super(AudioAssociationForm, self).save(*args, **kwargs)