Re: Problm using FileField with inline formsets (inlineformset_factory)

2017-10-05 Thread YusufSalahAdDin
You saved my ass, thanks!!!

El miércoles, 10 de septiembre de 2008, 13:46:20 (UTC+4), Daniel Roseman 
escribió:
>
> On Sep 10, 9:50 am, "c.poll...@bangor.ac.uk"  
> wrote: 
> > Hi 
> > 
> > I'm having a problem with inline formsets containing file field, i've 
> > had a good google but couldn't find an answer, so apolgies if this is 
> > a stupid or repetative question. 
> > 
> > I have a model Applicatant, which has a one to many relation with 
> > Education which contains a filefeild. My problem is that when django 
> > comes to validate the inline form education it reports that the field 
> > is empty, if i tell the model to allow empty feilds then the file is 
> > not saved 
> > 
> > Is it possible to use file fields with the inlineformset_factory or do 
> > i need to go at this another way? 
> > 
> > I have included my code, pretty simple and pretty much copied from the 
> > documentation: 
> > 
> > def myview(request): 
> > InlineFormSet = inlineformset_factory(Applicant, Education) 
> > applicant = Applicant.objects.get(pk=1) 
> > if request.method == 'POST': 
> > formset = InlineFormSet(request.POST, request.FILES, 
> > instance=applicant) 
> > if formset.is_valid(): 
> >Do stuff 
> >else: 
> >formset = InlineFormSet(instance=applicant) 
> > 
> >return render_to_response("mytemplate.html", { "formset": 
> > formset,}) 
> > 
> > where mytemplate.html is simply 
> > 
> >  
> > 
> > {{ formset.management_form }} 
> >  
> > {% for form in formset.forms %} 
> > {{ form.as_ul }} 
> > {% endfor %} 
> >  
> > 
> >  
> >  
> > 
> > Many than ks 
> > Charlotte 
>
>
> The problem isn't with Formsets, it's just that you haven't set your 
> enctype in the HTML form element. It should be: 
>  
>
> See 
> http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form
>  
> -- 
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87f723fa-9938-4472-b53e-a03111f0c946%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 'ImageFieldFile' object has no attribute 'startswith'

2015-05-21 Thread YusufSalahAdDin
I have the same problem doing feeds, can anyone help me?
Yes, i'm using sorl-thumbnail.

El lunes, 11 de agosto de 2008, 14:59:47 (UTC-5), Daehee escribió:
>
> Thank you for the prompt responses. I am using sorl-thumbnail on 
> Google Code, and with your tips I found the solution to the problem 
> based on the FileField refactoring here: 
> http://code.google.com/p/sorl-thumbnail/issues/detail?id=34 
>
> Daehee 
>
> On Aug 11, 3:37 pm, "Marty Alchin"  wrote: 
> > On Mon, Aug 11, 2008 at 3:22 PM, Daehee  wrote: 
> > > Hi, I'm using Django revision 8309. After I recently update to this 
> > > revision, it seems to break my code... Just wondering if anyone else 
> > > is having the same errors. I tried to roll back to a previous revision 
> > > but now the error seems stuck. Any help would be appreciated. 
> > 
> > This would have been introduced in revision 8244, with the FileField 
> > changes. Values for FileField are no longer raw strings, so they don't 
> > have the startswith() method anymore. I was told last night that some 
> > of the thumbnail apps rely on startswith(), and are thus breaking. 
> > 
> > The solution here is to update the thumbnail app to use the value's 
> > "name" attribute as the string it wants. 
> > 
> > -Gul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc8e4077-2d4e-4e89-836b-d337c841a9c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django smart-select

2015-02-08 Thread YusufSalahAdDin
I have the same question, Did you solve it?

El martes, 2 de agosto de 2011, 2:53:09 (UTC-5), Dr.Linux escribió:
>
> Hi all, 
>
> I'm so sorry for this e-mail. May be you answered similar questions 
> many times. But I really need your help to learn how it's works. 
>
> There is a little problem with third-level(?) models (or many times 
> related models) in admin area with django-smart-selects plugin. I 
> don't know what does matter :) 
>
> This my colors model 
>
> from django.db import models 
>
> class Colors(models.Model): 
>color_name = models.CharField(max_length=50 
> ) 
>
> def __unicode__(self): 
> return self.color_name 
>
> This my Cars models 
>
> from django.db import models 
>
> class Cars(models.Model): 
> car_model = models.CharField(max_length=50 
> ) 
> car_colors = models.ManytoManyField(Colors, related_name='Car 
> Colors') 
>
> def __unicode__(self): 
> return self.car_model 
> O.K. Let's see my CarsData Model. 
>
> This my CarsData models 
>
> from django.db import models 
>
> class CarsData(models.Model): 
> car_barcode= models.CharField(max_length=5 
> 0) 
> available_color = ChainedForeignKey( 
>Cars, 
>chained_field="car_model", 
>chained_model_field="car_colors", 
>show_all=False, 
>auto_choose=True 
>  ) 
>
> def __unicode__(self): 
> return self.car_barcode 
> My admin.py looks like that: 
>
> from django.contrib import admin 
> from django import forms 
> from myapp.models import * 
>
> class CarsDataAdminForm(forms.ModelForm): 
>
> class Meta: 
> model = CarsData 
> def __init__(self, *arg, **kwargs): 
> super(CarsDataAdminForm, self).__init__(*arg, **kwargs) 
> self.fields['available_color'].choices = 
> [(csc.id,csc.car_colors) for csc in Cars.objects.all()] 
>
> class CarsDataAdmin(admin.ModelAdmin): 
> form = CarsDataAdminForm 
>
> admin.site.register(CarsData,CarsDataAdmin) 
>
>
> Is there anyway to show in the ChoiceField 'just' color_name field 
> datas? I see just car_model because i have to set it : 
>
> def __unicode__(self): 
> return self.car_model 
>
>
> Can you please give me an example? 
>
> Many thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f97c76dd-52cc-49aa-a5dc-bd6d109be06c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How create a custom permission for a model?

2014-09-03 Thread YusufSalahAdDin
Don't works for me :'(

El lunes, 1 de septiembre de 2014 12:07:19 UTC-5, Collin Anderson escribió:
>
> > Can't create other users
> > Can't create other topics or subtopics
> These can be done using built in permissions and groups
>
> Something like this might work for the rest:
>
> class NewsAdmin(models.Model):
>
> def get_queryset(self, request):
> queryset = super(NewsAdmin, self).get_queryset(request):
> if request.user.groups.filter(name="Author").exist():  # is the 
> user an author?
>  queryset = queryset.filter(author=self.user)  # only allow 
> users to edit their own posts
> return queryset
>
> def get_readonly_fields(self, request, obj=None):
> readonly_fields = super(NewsAdmin, self).get_readonly_field(
> request, obj)
> if request.user.groups.filter(name="Author").exist():  # is the 
> user an author?
> readonly_fields += ['published']  # don't allow authors to 
> change the publish status
> return readonly_fields
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/16b7bc84-1ef7-407e-a6c1-14d07fe1de83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How create a custom permission for a model?

2014-09-02 Thread YusufSalahAdDin
Hi men, now i have my model is thus:

from django.core.mail import send_mail, mail_admins


from django.db import models
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User


from ckeditor.fields import RichTextField


from subtopic.models import Subtopic
from topic.models import Topic
from keywords.models import KeyWord


#Global Vars




# Create your models here.


class New(models.Model):
author = models.ForeignKey(User, verbose_name='Autor', related_name=
'news')
content = RichTextField(verbose_name='Contenido')
created_date = models.DateTimeField(auto_now_add=True, verbose_name='Fecha 
y Hora')
is_published = models.BooleanField(verbose_name='Publicada', default=
False,) #Nueva, para verificar si se publica o no
keywords = models.ManyToManyField(KeyWord, blank=True, 
verbose_name='Palabras 
Clave', related_name='news')
place = models.CharField(max_length=255, verbose_name='Lugar')
source = models.URLField(verbose_name='Fuente', blank=True)
subtopic = models.ForeignKey(Subtopic, verbose_name='Subtema', 
related_name='news') #Filtramos por Opinion para sacar todas las columnas
times_viewed = models.PositiveIntegerField(default=0, editable=False, 
verbose_name='Veces Vista' )
title = models.CharField(verbose_name='Título', max_length=255, unique=
True)
slug =  models.SlugField(verbose_name='Slug', max_length=100, unique=
True)
topic = models.ForeignKey(Topic, verbose_name='Tema', related_name=
'news', )


class Meta:
ordering = ['-created_date']
verbose_name_plural = 'Noticias'
verbose_name = 'Noticia'


permissions = (
("can_publish", "Puede publicar noticias"), #Can publish news
)

def first_image(self):
return self.images.first() # Siendo images el related_name en Image


def first_video(self):
return self.videos #Devuelve el video de la imagen


def get_absolute_url(self):
return reverse ('NewsDefaultView', args = [str(self.created_date.
strftime("%Y")), str(self.created_date.strftime("%m")), str(self.
created_date.strftime("%d")), str(self.slug)])


def get_all_keys(self):
keys_list = self.keywords.values_list('name', flat=True)
return str(keys_list).strip("'[]'").replace("'",'')


#def is_published(self): devuelve si la noticia ha sido pulicada para 
que salga en la lista de noticias


def __str__(self):
return self.title


def save(self):  #Definir metodo para guardar, validar y otros metodos 
del Slug
super(New, self).save() #Solo con este me funciona correctamente
if not self.id:
self.slug = slugify(self.title)
super(New, self).save()


def get_queryset(self, request):
queryset = super(New, self).get_queryset(request)
if request.user.groups.filter(name="Author").exist():  # is the 
user an author?
 queryset = queryset.filter(author=self.user)  # only allow 
users to edit their own posts
return queryset


def get_readonly_fields(self, request, obj=None):
readonly_fields = super(New, self).get_readonly_field(request, obj)
if request.user.groups.filter(name="Author").exist():  # is the 
user an author?
readonly_fields += ['is_published']  # don't allow authors to 
change the publish status
return readonly_fields


from django.db.models.signals import post_save
def send_notification(sender, **kwargs):
return   mail_admins('Nueva noticia espera por edición','Una nueva 
noticia ha sido creada y espera ser editada y publicada muy pronto, anda, 
te esperamos.', )


post_save.connect(send_notification, sender=New)


from permission import add_permission_logic
from permission.logics import AuthorPermissionLogic, StaffPermissionLogic
add_permission_logic(New, AuthorPermissionLogic(
field_name='author',
any_permission=False,
change_permission=True,
delete_permission=True,
))
add_permission_logic(New, StaffPermissionLogic(
any_permission=False,
change_permission=True,
delete_permission=True,
))


from django.core.cache import cache
from django.db.models.signals import post_save
from django.dispatch import receiver


from django.contrib.sessions.models import Session
@receiver(post_save)
def clear_cache(sender, **kwargs):
if sender != Session:
cache.clear()

But, don't works, the author user can change other news and can publish 
:'(, what i'm doing bad?

I can created a group in python code? in mod

Re: How create a custom permission for a model?

2014-09-02 Thread YusufSalahAdDin
Wel wel wel, my code is it :

news.models.py

class New(models.Model):
author = models.ForeignKey(User, verbose_name='Autor', related_name=
'news')
content = RichTextField(verbose_name='Contenido')
created_date = models.DateTimeField(auto_now_add=True, verbose_name='Fecha 
y Hora')
is_published = models.BooleanField(verbose_name='Publicada', default=
False,) #Nueva, para verificar si se publica o no
keywords = models.ManyToManyField(KeyWord, blank=True, 
verbose_name='Palabras 
Clave', related_name='news')
place = models.CharField(max_length=255, verbose_name='Lugar')
source = models.URLField(verbose_name='Fuente', blank=True)
subtopic = models.ForeignKey(Subtopic, verbose_name='Subtema', 
related_name='news') #Filtramos por Opinion para sacar todas las columnas
times_viewed = models.PositiveIntegerField(default=0, editable=False, 
verbose_name='Veces Vista' )
title = models.CharField(verbose_name='Título', max_length=255, unique=
True)
slug =  models.SlugField(verbose_name='Slug', max_length=100, unique=
True)
topic = models.ForeignKey(Topic, verbose_name='Tema', related_name=
'news', )


class Meta:
ordering = ['-created_date']
verbose_name_plural = 'Noticias'
verbose_name = 'Noticia'


permissions = (
("can_publish", "Puede publicar noticias"), #Can publish news
)

from permission import add_permission_logic
from permission.logics import AuthorPermissionLogic, StaffPermissionLogic
add_permission_logic(New, AuthorPermissionLogic(
field_name='author',
any_permission=False,
change_permission=True,
delete_permission=True,
))
add_permission_logic(New, StaffPermissionLogic(
any_permission=False,
change_permission=True,
delete_permission=True,
))


As you can see, i'm using django-permission.

What have i do ?

El lunes, 1 de septiembre de 2014 12:07:19 UTC-5, Collin Anderson escribió:
>
> > Can't create other users
> > Can't create other topics or subtopics
> These can be done using built in permissions and groups
>
> Something like this might work for the rest:
>
> class NewsAdmin(models.Model):
>
> def get_queryset(self, request):
> queryset = super(NewsAdmin, self).get_queryset(request):
> if request.user.groups.filter(name="Author").exist():  # is the 
> user an author?
>  queryset = queryset.filter(author=self.user)  # only allow 
> users to edit their own posts
> return queryset
>
> def get_readonly_fields(self, request, obj=None):
> readonly_fields = super(NewsAdmin, self).get_readonly_field(
> request, obj)
> if request.user.groups.filter(name="Author").exist():  # is the 
> user an author?
> readonly_fields += ['published']  # don't allow authors to 
> change the publish status
> return readonly_fields
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8831c56-a326-447a-b296-214dc8f3cd3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How create a custom permission for a model?

2014-08-31 Thread YusufSalahAdDin
Hi, how are you?

I have the next question:

Good Nights, this is a question, not a issue.

I need have to user's types: a default admin in django, and a author.
Default admin have a aditional permission: can publish a news.
And for author user i have the next constrains:

   - Can't publish news.
  - Can't create other users
  - Can't create other topics or subtopics
  - Can create a new, but, only can edit or delete his own news, no 
  other user's news.
   
I talked with other friend and he say me that i need per-objetcs 
permissions, but, i don't know how do this.

Can you help me?


Now i'm ussing django-permission, but i don't know how do a custom 
can_publish permission.


I wan't cread a custom view, no, i want used django's admin, news model 
have a boolean field, is_published, i want that if the user is Author, can 
modify this field, and if is admin, can modify this field, can anyone help 
me?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/06752534-dd11-4422-a0cb-25cc81ca077c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.