Re: Generic relations swamp

2009-04-14 Thread zayatzz

Ok your idea worked just fine, but i keep coming up with new
questions :)

The result of it was that when i opened poll i got poll with name


So i wrote something (i dont know how its called - model instance?
model manager?) to retrieve the actual value of translation and my
poll model looks like this now :
class Poll(models.Model):
name = generic.GenericRelation(Trans)
pub_date = models.DateTimeField('date published')
active = models.BooleanField()
def __unicode__(self):
return unicode(self.name)
def tname(self):
q = Trans.objects.filter(poll = self)
q = q.get(keel = 1)
t = q.name
return t

Can this query also be shorter? and better? cause the first line seems
not to filter out anything at all.

Another one - this might solve the problem for displaying poll names
in list view, but when im creating questions for this poll, then in
the selectbox where i choose to which poll question belongs to i still
have poll name as
.
How could that be changed? Can it be changed withing admin.py of my
app?

Alan

On Apr 14, 3:45 pm, matehat  wrote:
> Sorry about the last post (was a little tired from a sleepless night
> of solving problems in physics ...). I think you can solve the issue
> by putting "return unicode(self.name)" instead of "return self.name"
> in all of the __unicode__ method of your models. The things is that
> you must make sure to return unicode object in that method.
>
> Another thing that pops in my mind from inspecting your code is that
> line in TranslationInline,
>
> >class TranslationInline(generic.GenericTabularInline):
> >        model = Trans
> >        extra = len(lang.objects.all())
>
> where it would be more efficient to do :
>
> extra = lang.objects.count()
>
> But that's just optimization stuff...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-14 Thread zayatzz



On Apr 14, 3:45 pm, matehat  wrote:
> Sorry about the last post (was a little tired from a sleepless night
> of solving problems in physics ...). I think you can solve the issue
> by putting "return unicode(self.name)" instead of "return self.name"
> in all of the __unicode__ method of your models. The things is that
> you must make sure to return unicode object in that method.
>
> Another thing that pops in my mind from inspecting your code is that
> line in TranslationInline,
>
> >class TranslationInline(generic.GenericTabularInline):
> >        model = Trans
> >        extra = len(lang.objects.all())
>
> where it would be more efficient to do :
>
> extra = lang.objects.count()
>
> But that's just optimization stuff...

Thanks for the info and tip :). I'll test it as soon as i get home.

Perhaps you can provide little more help about the django admin. That
extra there is meant to provide exactly right amount of fields for
each object, that i create, but if you use one saving option of django
admin you get more fields, which are completely unnecessary. Is there
a simple way to limit the amount of those fields and nothing more?

Alan.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-14 Thread matehat

Sorry about the last post (was a little tired from a sleepless night
of solving problems in physics ...). I think you can solve the issue
by putting "return unicode(self.name)" instead of "return self.name"
in all of the __unicode__ method of your models. The things is that
you must make sure to return unicode object in that method.

Another thing that pops in my mind from inspecting your code is that
line in TranslationInline,

>class TranslationInline(generic.GenericTabularInline):
>model = Trans
>extra = len(lang.objects.all())

where it would be more efficient to do :

extra = lang.objects.count()

But that's just optimization stuff...


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-12 Thread zayatzz

Admin for language:
from kyss.front.models import lang
from django.contrib import admin
class FrontAdmin(admin.ModelAdmin):
fieldsets = [
('General info', {'fields': ['name', 'short', 'locale', 
'encoding',
'url', 'fdef', 'bdef']}),
('SEO stuff', {'fields': ['title', 'metadesc', 'metakeyw',
'websitename', 'websiteslogan']}),
]

admin.site.register(lang, FrontAdmin)

Admin for poll and translations:
from kyss.poll.models import Poll
from kyss.poll.models import Question
from kyss.poll.models import Choice
from kyss.poll.models import Trans
from kyss.front.models import lang
from django.contrib import admin
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

class QuestionInline(admin.TabularInline):
model = Question
extra = 2

class ChoiceInline(admin.TabularInline):
model = Choice
extra = 4

class TranslationInline(generic.GenericTabularInline):
model = Trans
extra = len(lang.objects.all())

class TransAdmin(admin.ModelAdmin):
list_display = ['id', 'name']

class QuestionAdmin(admin.ModelAdmin):
inlines = [ TranslationInline ]

class ChoiceAdmin(admin.ModelAdmin):
inlines = [ TranslationInline ]

class PollAdmin(admin.ModelAdmin):
fieldsets = [
('Date information', {'fields': ['pub_date'], 'classes':
['collapse']}),
('Is this poll active', {'fields': ['active'] }),
]
inlines = [ TranslationInline ]

admin.site.register(Poll, PollAdmin)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Choice, ChoiceAdmin)
admin.site.register(Trans, TransAdmin)

Models have not been changed.

Alan.
On Apr 12, 4:27 pm, matehat  wrote:
> Hi,
>
> can you show us the code for each of your admin classes? This probably
> has something to do with some method overrides, but I can't say much
> about the cause of your problem from the error message you gave...
>
> Cheers
>
> Mathieu
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-12 Thread matehat

Hi,

can you show us the code for each of your admin classes? This probably
has something to do with some method overrides, but I can't say much
about the cause of your problem from the error message you gave...

Cheers

Mathieu
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-11 Thread zayatzz

I realise im kind of spamming here, but does nobody really has
encountered similar problem?

Alan.

On Apr 11, 12:07 am, zayatzz  wrote:
> Ok, I did some search on web and i took closer look at the
> errormessage. :
>
> Request information
> GET
>
> No GET data
> POST
> Variable        Value
> poll-trans-content_type-object_id-0-keel
> u'1'
> poll-trans-content_type-object_id-0-id
> u''
> poll-trans-content_type-object_id-1-keel
> u'2'
> poll-trans-content_type-object_id-TOTAL_FORMS
> u'2'
> _save
> u'Save'
> poll-trans-content_type-object_id-1-name
> u'Pollname in russian'
> pub_date_1
> u'23:45:15'
> pub_date_0
> u'2009-04-10'
> poll-trans-content_type-object_id-1-id
> u''
> active
> u'on'
> poll-trans-content_type-object_id-0-name
> u'Pollname in estonian'
> poll-trans-content_type-object_id-INITIAL_FORMS
> u'0'
>
> If i understand this correctly then the content object id is not
> beeing saved - it does not save the id of the poll with the
> translations. Is this correct? And how can i fix this?
>
> I found many threads about incomplete generic relations support in
> admin - they were from '07 or so, so the things could be different.
> And i found this :http://djangoplugables.com/projects/django-genericadmin/
>
> Could this be of any use?
>
> Would anything else help?
>
> Thanks!
> Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-10 Thread zayatzz

Ok, I did some search on web and i took closer look at the
errormessage. :

Request information
GET

No GET data
POST
VariableValue
poll-trans-content_type-object_id-0-keel
u'1'
poll-trans-content_type-object_id-0-id
u''
poll-trans-content_type-object_id-1-keel
u'2'
poll-trans-content_type-object_id-TOTAL_FORMS
u'2'
_save
u'Save'
poll-trans-content_type-object_id-1-name
u'Pollname in russian'
pub_date_1
u'23:45:15'
pub_date_0
u'2009-04-10'
poll-trans-content_type-object_id-1-id
u''
active
u'on'
poll-trans-content_type-object_id-0-name
u'Pollname in estonian'
poll-trans-content_type-object_id-INITIAL_FORMS
u'0'

If i understand this correctly then the content object id is not
beeing saved - it does not save the id of the poll with the
translations. Is this correct? And how can i fix this?

I found many threads about incomplete generic relations support in
admin - they were from '07 or so, so the things could be different.
And i found this :
http://djangoplugables.com/projects/django-genericadmin/

Could this be of any use?

Would anything else help?

Thanks!
Alan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-10 Thread zayatzz

does anyone know how to solve this problem?

Alan

On 9 apr, 21:54, zayatzz  wrote:
> Thanks.
>
> That worked for enabling translations for poll names - i had to insert
> 'from django.contrib.contenttypes import generic', right?
> It worked, but it raised few more questions. When creating poll i get
> lines for name translations now and in front of each of them there is
> language drop down menu, where i can choose to which language this
> translation belongs to. How can i replace that with just language
> name. Do i have to create some kind of loop for that view (/poll/poll/
> add), so i just get correct amount of name translations and nothing
> else?
>
> in any case it worked, but when i tried to save that poll i got this
> error :
>
> Request URL:    http://127.0.0.1:8000/admin/poll/poll/add/
> Exception Type:         TypeError
> Exception Value:        coercing to Unicode: need string or buffer,
> GenericRelatedObjectManager found
>
> Runnin search on that error i found 
> :http://mail.python.org/pipermail/python-list/2006-July/566947.html
>
> Does that mean, that connection between translation and poll name
> failed or something else at all?
>
> Alan.
>
> On Apr 9, 6:36 pm, matehat  wrote:
>
> > First of all, the ModelAdmin needs to know about how to handle the
> > generic relations and whether you even need them to appear. You need
> > to subclass "generic.GenericTabularInline" (in the same way you
> > subclassed "admin.ModelAdmin") and specify fields you want to be able
> > to edit on that Trans object (probably only the "name" field if I
> > understood right) and the actual model (here Trans). Then, you'd need
> > to add the 'inlines' attribute to your PollAdmin and add the
> > GenericTabularInline subclass. So your code should look something
> > like :
>
> >http://dpaste.com/30763/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-09 Thread matehat

First of all, the ModelAdmin needs to know about how to handle the
generic relations and whether you even need them to appear. You need
to subclass "generic.GenericTabularInline" (in the same way you
subclassed "admin.ModelAdmin") and specify fields you want to be able
to edit on that Trans object (probably only the "name" field if I
understood right) and the actual model (here Trans). Then, you'd need
to add the 'inlines' attribute to your PollAdmin and add the
GenericTabularInline subclass. So your code should look something
like :

http://dpaste.com/30763/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---