Re: view queryset object in admin view

2015-04-13 Thread makayabou
Thank you Jani,
it solved it!
I was just loosing around, I finally got it...
thanks all

On Monday, April 13, 2015 at 2:29:36 PM UTC+2, makayabou wrote:
>
> I made a clearer and full sample code.
> When I use the code as is, I get results in a poor readable
> format in PCAdmin view
> [, ] 
> <http://localhost:8002/admin/users/pc/1/>
> although I just want Jean Dubois, martin franck
>
> Thanks for help
>
> My models.py
> [code]
> from django.db import models
>
> class PC(models.Model):
> os= models.CharField(max_length=5, null=True, blank=True)
> def users(self):
> pc = self.user_set.all()
> return pc
> # If I use loop "for", I get a great unicode view, but only the first 
> result...
> # for o in pc:
> # return o.__unicode__()
> def __unicode__(self):
> return 'pc  '+ unicode(self.id)+ ' - ' + self.os
>
> class User(models.Model):
> name=models.CharField(max_length=20, null=True, blank=True)
> mypc = models.ForeignKey(PC, null=True,blank=True)
> def __unicode__(self):
> return self.name
> [/code]
>
> My admin.py:
> [code]
> from django.contrib import admin
> from users.models import User, PC
>
> class PCAdmin(admin.ModelAdmin):
> list_display = ('users','id')
> 
> class UserAdmin(admin.ModelAdmin):  
> list_display = ('name','mypc')
> admin.site.register(User, UserAdmin)
> admin.site.register(PC, PCAdmin)
> /]
>
>
>
>
> On Monday, April 13, 2015 at 1:12:55 PM UTC+2, makayabou wrote:
>>
>> Hello,
>> thanks for reply,
>> of course attribute name was defined, I just ommited to past it!
>>
>> Here's code:
>>
>> [code]
>> #In models.py:
>>
>>
>> class PC(models.Model):
>> def users(self):
>> pc = self.user_set.all()
>> for o in pc:
>> return o.__unicode__
>> def __unicode__(self):
>> return 'pc '+unicode(self.id)+' - '+self.os()
>>
>>
>> class User(models.Model):
>> name=models.TextField()
>> mypc = models.ForeignKey(PC)
>> def __unicode__(self):
>> return self.name   
>>
>>
>> #In admin.py:
>>
>>
>> class PcAdmin(admin.ModelAdmin):
>> list_display = ('users','id')
>> [/code]
>>
>> Still have this weird print: 
>> >
>>
>> instead of:
>> Jean Dubois
>>
>> thank you for help
>>
>> Le lundi 13 avril 2015 07:57:00 UTC+2, Avraham Serour a écrit :
>>>
>>> Well, your class User doesn't have an attribute name you are using on 
>>> the method __unicode__, you should define and set the attribute name with 
>>> something like a textfield
>>> On Apr 13, 2015 3:21 AM, "makayabou" <maka...@gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> Sorry for the previous send unattended...
>>>>
>>>> I have problems trying to print values of a QUerySet Object in Admin 
>>>> View.
>>>>
>>>> In admin view, I would like to get a clear list of results,
>>>>> as defined in __unicode__ from class User.
>>>>> Instead, I get:
>>>>>
>>>>> >
>>>>>
>>>>> I just need Jean Dubois..
>>>>>
>>>>> Here's the code:
>>>>>
>>>>> #In models.py:
>>>>>
>>>>>
>>>>> class PC(models.Model):
>>>>>  def users(self):
>>>>>  pc = self.user_set.all()
>>>>>  for o in pc:
>>>>>  return o.__unicode__
>>>>>  def __unicode__(self):
>>>>>  return 'pc '+unicode(self.id)+' - '+self.os()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> class User(models.Model):
>>>>> mypc = models.ForeignKey(PC)
>>>>> def __unicode__(self):
>>>>> return self.name   
>>>>>
>>>>>
>>>>> #In admin.py:
>>>>>
>>>>>
>>>>> class PcAdmin(admin.ModelAdmin):
>>>>> list_display = ('users','id')
>>>>>
>>>>>
>>>> Thanks for your help. 
>>>>
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>

-- 
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/b929d114-e364-4864-926c-0dc0ec5b91dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: view queryset object in admin view

2015-04-13 Thread makayabou
I made a clearer and full sample code.
When I use the code as is, I get results in a poor readable
format in PCAdmin view
[, ] 
<http://localhost:8002/admin/users/pc/1/>
although I just want Jean Dubois, martin franck

Thanks for help

My models.py
[code]
from django.db import models

class PC(models.Model):
os= models.CharField(max_length=5, null=True, blank=True)
def users(self):
pc = self.user_set.all()
return pc
# If I use loop "for", I get a great unicode view, but only the first 
result...
# for o in pc:
# return o.__unicode__()
def __unicode__(self):
return 'pc  '+ unicode(self.id)+ ' - ' + self.os

class User(models.Model):
name=models.CharField(max_length=20, null=True, blank=True)
mypc = models.ForeignKey(PC, null=True,blank=True)
def __unicode__(self):
return self.name
[/code]

My admin.py:
[code]
from django.contrib import admin
from users.models import User, PC

class PCAdmin(admin.ModelAdmin):
list_display = ('users','id')

class UserAdmin(admin.ModelAdmin):  
list_display = ('name','mypc')
admin.site.register(User, UserAdmin)
admin.site.register(PC, PCAdmin)
/]




On Monday, April 13, 2015 at 1:12:55 PM UTC+2, makayabou wrote:
>
> Hello,
> thanks for reply,
> of course attribute name was defined, I just ommited to past it!
>
> Here's code:
>
> [code]
> #In models.py:
>
>
> class PC(models.Model):
> def users(self):
> pc = self.user_set.all()
> for o in pc:
> return o.__unicode__
> def __unicode__(self):
> return 'pc '+unicode(self.id)+' - '+self.os()
>
>
> class User(models.Model):
> name=models.TextField()
> mypc = models.ForeignKey(PC)
> def __unicode__(self):
> return self.name   
>
>
> #In admin.py:
>
>
> class PcAdmin(admin.ModelAdmin):
> list_display = ('users','id')
> [/code]
>
> Still have this weird print: 
> >
>
> instead of:
> Jean Dubois
>
> thank you for help
>
> Le lundi 13 avril 2015 07:57:00 UTC+2, Avraham Serour a écrit :
>>
>> Well, your class User doesn't have an attribute name you are using on the 
>> method __unicode__, you should define and set the attribute name with 
>> something like a textfield
>> On Apr 13, 2015 3:21 AM, "makayabou" <maka...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Sorry for the previous send unattended...
>>>
>>> I have problems trying to print values of a QUerySet Object in Admin 
>>> View.
>>>
>>> In admin view, I would like to get a clear list of results,
>>>> as defined in __unicode__ from class User.
>>>> Instead, I get:
>>>>
>>>> >
>>>>
>>>> I just need Jean Dubois..
>>>>
>>>> Here's the code:
>>>>
>>>> #In models.py:
>>>>
>>>>
>>>> class PC(models.Model):
>>>>  def users(self):
>>>>  pc = self.user_set.all()
>>>>  for o in pc:
>>>>  return o.__unicode__
>>>>  def __unicode__(self):
>>>>  return 'pc '+unicode(self.id)+' - '+self.os()
>>>>
>>>>
>>>>
>>>>
>>>> class User(models.Model):
>>>> mypc = models.ForeignKey(PC)
>>>> def __unicode__(self):
>>>> return self.name   
>>>>
>>>>
>>>> #In admin.py:
>>>>
>>>>
>>>> class PcAdmin(admin.ModelAdmin):
>>>> list_display = ('users','id')
>>>>
>>>>
>>> Thanks for your help. 
>>>
>>> -- 
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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/9b1ce52e-edb8-4811-ad34-e5407723831c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: view queryset object in admin view

2015-04-13 Thread Jani Tiainen
Hi, there are several flaws in your code.


On Mon, 13 Apr 2015 04:12:55 -0700 (PDT)
makayabou <makaya...@gmail.com> wrote:

> Hello,
> thanks for reply,
> of course attribute name was defined, I just ommited to past it!
> 
> Here's code:
> 
> [code]
> #In models.py:
> 
> 
> class PC(models.Model):
> def users(self):
> pc = self.user_set.all()
> for o in pc:
> return o.__unicode__

Here you return first (only first) __unicode__ method of "o" object.
Wild guess is that you want to do something like this:

def users(self):
return u', '.join([unicode(u) for u in self.user_set.all()])  ## Return 
comma separated list of users

> def __unicode__(self):
> return 'pc '+unicode(self.id)+' - '+self.os()

You declare unicode method, yet your return is a bytestring. You should put 
u-prefix before texts.

> 
> class User(models.Model):
> name=models.TextField()
> mypc = models.ForeignKey(PC)
> def __unicode__(self):
> return self.name   
> 
> 
> #In admin.py:
> 
> 
> class PcAdmin(admin.ModelAdmin):
> list_display = ('users','id')
> [/code]
> 
> Still have this weird print: 
> >
> 

That's correct output - first object and it's __unicode__ method - that's what 
you return in your code.

> instead of:
> Jean Dubois
> 
> thank you for help
> 
> Le lundi 13 avril 2015 07:57:00 UTC+2, Avraham Serour a écrit :
> >
> > Well, your class User doesn't have an attribute name you are using on the 
> > method __unicode__, you should define and set the attribute name with 
> > something like a textfield
> > On Apr 13, 2015 3:21 AM, "makayabou" <maka...@gmail.com > 
> > wrote:
> >
> >> Hello,
> >>
> >> Sorry for the previous send unattended...
> >>
> >> I have problems trying to print values of a QUerySet Object in Admin View.
> >>
> >> In admin view, I would like to get a clear list of results,
> >>> as defined in __unicode__ from class User.
> >>> Instead, I get:
> >>>
> >>> >
> >>>
> >>> I just need Jean Dubois..
> >>>
> >>> Here's the code:
> >>>
> >>> #In models.py:
> >>>
> >>>
> >>> class PC(models.Model):
> >>>  def users(self):
> >>>  pc = self.user_set.all()
> >>>  for o in pc:
> >>>  return o.__unicode__
> >>>  def __unicode__(self):
> >>>  return 'pc '+unicode(self.id)+' - '+self.os()
> >>>
> >>>
> >>>
> >>>
> >>> class User(models.Model):
> >>> mypc = models.ForeignKey(PC)
> >>> def __unicode__(self):
> >>> return self.name   
> >>>
> >>>
> >>> #In admin.py:
> >>>
> >>>
> >>> class PcAdmin(admin.ModelAdmin):
> >>> list_display = ('users','id')
> >>>
> >>>
> >> Thanks for your help. 
> >>
> >> -- 
> >> 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...@googlegroups.com .
> >> To post to this group, send email to django...@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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
> >>  
> >> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
> >> .
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
> 
> -- 
> 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/58ba4264-a9b1-4a7e-a86c-cc9d145deaab%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150413142244.252d5d6d%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: view queryset object in admin view

2015-04-13 Thread makayabou
Hello,
thanks for reply,
of course attribute name was defined, I just ommited to past it!

Here's code:

[code]
#In models.py:


class PC(models.Model):
def users(self):
pc = self.user_set.all()
for o in pc:
return o.__unicode__
def __unicode__(self):
return 'pc '+unicode(self.id)+' - '+self.os()


class User(models.Model):
name=models.TextField()
mypc = models.ForeignKey(PC)
def __unicode__(self):
return self.name   


#In admin.py:


class PcAdmin(admin.ModelAdmin):
list_display = ('users','id')
[/code]

Still have this weird print: 
>

instead of:
Jean Dubois

thank you for help

Le lundi 13 avril 2015 07:57:00 UTC+2, Avraham Serour a écrit :
>
> Well, your class User doesn't have an attribute name you are using on the 
> method __unicode__, you should define and set the attribute name with 
> something like a textfield
> On Apr 13, 2015 3:21 AM, "makayabou" <maka...@gmail.com > 
> wrote:
>
>> Hello,
>>
>> Sorry for the previous send unattended...
>>
>> I have problems trying to print values of a QUerySet Object in Admin View.
>>
>> In admin view, I would like to get a clear list of results,
>>> as defined in __unicode__ from class User.
>>> Instead, I get:
>>>
>>> >
>>>
>>> I just need Jean Dubois..
>>>
>>> Here's the code:
>>>
>>> #In models.py:
>>>
>>>
>>> class PC(models.Model):
>>>  def users(self):
>>>  pc = self.user_set.all()
>>>  for o in pc:
>>>  return o.__unicode__
>>>  def __unicode__(self):
>>>  return 'pc '+unicode(self.id)+' - '+self.os()
>>>
>>>
>>>
>>>
>>> class User(models.Model):
>>> mypc = models.ForeignKey(PC)
>>> def __unicode__(self):
>>> return self.name   
>>>
>>>
>>> #In admin.py:
>>>
>>>
>>> class PcAdmin(admin.ModelAdmin):
>>> list_display = ('users','id')
>>>
>>>
>> Thanks for your help. 
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/58ba4264-a9b1-4a7e-a86c-cc9d145deaab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: view queryset object in admin view

2015-04-12 Thread Avraham Serour
Well, your class User doesn't have an attribute name you are using on the
method __unicode__, you should define and set the attribute name with
something like a textfield
On Apr 13, 2015 3:21 AM, "makayabou" <makaya...@gmail.com> wrote:

> Hello,
>
> Sorry for the previous send unattended...
>
> I have problems trying to print values of a QUerySet Object in Admin View.
>
> In admin view, I would like to get a clear list of results,
>> as defined in __unicode__ from class User.
>> Instead, I get:
>>
>> >
>>
>> I just need Jean Dubois..
>>
>> Here's the code:
>>
>> #In models.py:
>>
>>
>> class PC(models.Model):
>>  def users(self):
>>  pc = self.user_set.all()
>>  for o in pc:
>>  return o.__unicode__
>>  def __unicode__(self):
>>  return 'pc '+unicode(self.id)+' - '+self.os()
>>
>>
>>
>>
>> class User(models.Model):
>> mypc = models.ForeignKey(PC)
>> def __unicode__(self):
>> return self.name
>>
>>
>> #In admin.py:
>>
>>
>> class PcAdmin(admin.ModelAdmin):
>> list_display = ('users','id')
>>
>>
> Thanks for your help.
>
> --
> 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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAFWa6tLo5McP%3D2TS92a%2BkiUYpJKFTG9Agh1WzySuAaGdHAFrgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: view queryset object in admin view

2015-04-12 Thread makayabou
Hello,

Sorry for the previous send unattended...

I have problems trying to print values of a QUerySet Object in Admin View.

In admin view, I would like to get a clear list of results,
> as defined in __unicode__ from class User.
> Instead, I get:
>
> >
>
> I just need Jean Dubois..
>
> Here's the code:
>
> #In models.py:
>
>
> class PC(models.Model):
>  def users(self):
>  pc = self.user_set.all()
>  for o in pc:
>  return o.__unicode__
>  def __unicode__(self):
>  return 'pc '+unicode(self.id)+' - '+self.os()
>
>
>
>
> class User(models.Model):
> mypc = models.ForeignKey(PC)
> def __unicode__(self):
> return self.name   
>
>
> #In admin.py:
>
>
> class PcAdmin(admin.ModelAdmin):
> list_display = ('users','id')
>
>
Thanks for your help. 

-- 
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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


view queryset object in admin view

2015-04-12 Thread makayabou
# Je voudrais, dans ma vue admin, avoir un affichage clair des maintenances
# effectuées, qui corresponde à __unicode__ définie dans Ordi
# mais j'ai :  
In admin view, I would like to get a clear list of results,
as defined in __unicode__ from class User.
Instead, I get:

>

I just need Jean Dubois..

Here's the code:

#In models.py:


class PC(models.Model):
 def users(self):
 pc = self.user_set.all()
 for o in pc:
 return o.__unicode__
 def __unicode__(self):
 return 'pc '+unicode(self.id)+' - '+self.os()




class User(models.Model):
mypc = models.ForeignKey(PC)
def __unicode__(self):
return self.name   


#In admin.py:


class PcAdmin(admin.ModelAdmin):
list_display = ('users','id')


-- 
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/ecc9f29c-17bf-4de2-82be-b27266671ddf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.