Commit d5cfdde4ec07fd3976e8624c47b2595818864491
1 parent
452de87f
Exists in
master
and in
2 other branches
Started news app and some adjusts iniciated
Showing
9 changed files
with
47 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +from django import forms | ||
2 | +from django.utils.translation import ugettext_lazy as _ | ||
3 | + | ||
4 | +from .models import News | ||
5 | + | ||
6 | +class NewsForm(forms.ModelForm): | ||
7 | + class Meta: | ||
8 | + model = News | ||
9 | + fields = ['title','image','content'] | ||
10 | + widgets = { | ||
11 | + 'content': forms.Textarea, | ||
12 | + } |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +from django.db import models | ||
2 | + | ||
3 | +# Create your models here. | ||
4 | +from autoslug.fields import AutoSlugField | ||
5 | + | ||
6 | +from django.utils.translation import ugettext_lazy as _ | ||
7 | +from django.core.exceptions import ValidationError | ||
8 | + | ||
9 | + | ||
10 | +def validate_img_extension(value): | ||
11 | + valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png'] | ||
12 | + | ||
13 | + if hasattr(value.file, 'content_type'): | ||
14 | + if not value.file.content_type in valid_formats: | ||
15 | + raise ValidationError(_('File not supported.')) | ||
16 | + | ||
17 | +class News(models.Model): | ||
18 | + title = models.CharField( _("Name"), unique = True,max_length= 200) | ||
19 | + slug = AutoSlugField(_("Slug"),populate_from='title',unique=True) | ||
20 | + image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension]) | ||
21 | + content = models.TextField(_('Description')) |