Re: OneToOne? Inheritance? Another solution for nested model relationships?

2014-05-30 Thread Leonardo Giordani
I see your point. In this case I'd recommend giving Researcher two foreign
keys, one towards a Student model and one towards a Staff one, then add
some logic to the model to easily check the actual specialization or to
convert it among them. Basically you get a Researcher that "owns" a Student
or a Staff role.

Does this fit better? Let me know

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub page
 - My Coderwall profile



2014-05-28 14:37 GMT+02:00 Daniele Procida :

> On Wed, May 28, 2014, Leonardo Giordani 
> wrote:
>
> >I usually solve such issues with Inheritance. I feel comfortable with it
> >because it lets me (in your example) to manage both ResearchStudent and
> >ResearchStaff independently, while keeping the Researcher parent model
> >available to deal with "global" queries and data interaction.
>
> It it were a case where abstract inheritance would work, I would agree.
> Unfortunately, the Researcher model can't be abstract (because it has its
> own relations with Publications).
>
> If I use multi-table inheritance, that solves part of the problem. However
> I don't know how well it would work if I have a Researcher, who at some
> point needs to be a ResearchStudent and maybe later becomes ResearchStaff.
>
> Regards,
>
> Daniele
>
> --
> 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/20140528123744.1377784185%40smtpauth.cf.ac.uk
> .
> 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/CAEhE%2BOkKVXb-QKP5KNB003Q%3DrTGxane5vHMAwJETokbq%3D1H87A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and Rails

2014-05-30 Thread Derek
Hi Enrique

Apart from the mailing list, a good place to keep up with Python and Django 
in general is the http://www.pythonweekly.com/ newsletter.  Its not long, 
is well-structured and  will help give some idea of the current  "buzz" ...

(PS Not everyone is convinced that Rails is "faster" - 
http://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=query&b=1&s=2&f=so-0-0-0
 
but I won't debate the "cooler" part though)

On Thursday, 29 May 2014 20:31:17 UTC+2, Enrique Shadah wrote:
>
> Thanks everyone.  You've confirmed what I have suspected. Also, an MIT CS 
> prof. suggested today to stick to python/django.  Rails may be fast and 
> cool, but that it may offer too much "magic" to really know what's going on 
> and debug if needed.  For a newbie like me, I need explicit guidance and 
> clear thinking. Maybe when I reach django ninja status, I can try other 
> more esoteric frameworks.
>
>
> On Thursday, May 29, 2014 9:36:05 AM UTC-4, willyhakim wrote:
>>
>> Django learning curve might be steeper than Rails, but it will make you a 
>> better web dev in the long run. Check out realpython.com and maybe start 
>> by getting a solid foundation on python
>>
>>
>> On Wednesday, May 28, 2014 10:55:58 PM UTC-5, Enrique Shadah wrote:
>>>
>>> Hi all,
>>>
>>> I am learning Django after trying once with Rails. As I am a newbie to 
>>> software development, Rails seemed more obscure and difficult to digest. I 
>>> chose to learn Django because Python is easier to understand than Ruby (at 
>>> least to me) and because I thought it had a bigger or more enthusiastic 
>>> community to learn from.
>>>
>>> However, I am finding that Django has some limitations Rails does not.  
>>> One is that its community is fading (or at least it feels that way).  
>>> Another is that Rails seems to be better at automating mundane tasks 
>>> (staying true to the DRY principle). For example, rake db migrate can 
>>> add/subtract fields on table without writing any sql.  Django can add 
>>> fields and tables with syncdb, but if I need to subtract fields or change 
>>> whether the field is required or not, I am faced to writing sql.  This 
>>> seems pretty silly given that new site is constantly changing, thus models 
>>> will suffer many changes as users suggest/reject features.  
>>>
>>> These are just two limitations off the top of my head.  I am sure Django 
>>> is awesome, but could anyone share their views on whether I should just 
>>> learn Rails off the bat instead of going the Django then Rails route?
>>>
>>

-- 
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/a444dc10-9cda-4bfb-aab2-6dc31c4ef099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
Hello,

In my django admin page I want to hide some filelds from users if a special 
field value is set. I have tried different solutions to solve my problem 
but is stucked and hope someone can help me,

If you look at my model I want to hide the field readinessDescription if 
readiness value is False (no), when the user log into admin page. 

In model.py:
class RequestForChange (models.Model):
rfc = models.AutoField (primary_key=True, help_text="This is the grey text")
heading = models.CharField("Heading", max_length=50)
   readiness = models.NullBooleanField("Readiness", blank=True, 
null=True)
   readinessDescription = models.TextField("Description of readiness", 
max_length=250, blank=True, null=True) 


I found some hints on the web about using get_form from my 
RequestForChangeAdmin page, but it won't work because i get this error 
'NoneType' object has no attribute 'readiness'


Here is what I have in admin.py:

class RequestForChangeAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
list_display = ('rfc', 'heading', 'enviroment', 'status')
search_fields = ('changeId',)
list_filter = ('enviroment', 'acceptAT', 'status')
date_hierarchy = 'criticalDate'
inline = [RequestForChangeInline]
 def get_form(self, request, obj=None, **kwargs):
form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
 print obj
if obj.readiness == True:
self.exclude = ("readinessDescription", )
form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
return form

-- 
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/2c1d74b1-c03c-4c2b-b8db-7d44a06531c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
Is 'readiness' really a tri-state flag?

Anyway you may want to test if obj.readiness exists, and is TRUE.

if obj.readiness and obj.readiness == TRUE:


HTH,
Tim



On Fri, May 30, 2014 at 7:57 AM, Hilde Rafaelsen 
wrote:

> Hello,
>
> In my django admin page I want to hide some filelds from users if a
> special field value is set. I have tried different solutions to solve my
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription if
> readiness value is False (no), when the user log into admin page.
>
> In model.py:
> class RequestForChange (models.Model):
> rfc = models.AutoField (primary_key=True, help_text="This is the grey
> text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True,
> null=True)
>readinessDescription = models.TextField("Description of readiness",
> max_length=250, blank=True, null=True)
>
>
> I found some hints on the web about using get_form from my
> RequestForChangeAdmin page, but it won't work because i get this error
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
> search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
> date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>  def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>  print obj
> if obj.readiness == True:
> self.exclude = ("readinessDescription", )
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
> return form
>
> --
> 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/2c1d74b1-c03c-4c2b-b8db-7d44a06531c4%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

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


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen


Hi,

 

Thanks for the response.

 

What do you mean by tri-state?

 

I changed my get_form to this:

def get_form(self, request, obj=None, **kwargs):

   form = super(RequestForChangeAdmin, 
self).get_form(request, obj, **kwargs)

   if obj:

   if obj.readiness == True:

   self.exclude 
= ("readinessDescription", )

   form = 
super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)

   return form

 

No my code run without errors, but nothing happpends though ☺

 

I have tried to change the readiness filds to yes and no, but the field 
readiness descriptions is always displayed. Maybe it is not possibly to get 
a fields attribute value from admin before the admin form is posted or 
stored in database? Do you know?

 

Regards,

Hilde from Norway

On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hello,
>
> In my django admin page I want to hide some filelds from users if a 
> special field value is set. I have tried different solutions to solve my 
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription if 
> readiness value is False (no), when the user log into admin page. 
>
> In model.py:
> class RequestForChange (models.Model):
> rfc = models.AutoField (primary_key=True, help_text="This is the grey 
> text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True, 
> null=True)
>readinessDescription = models.TextField("Description of readiness", 
> max_length=250, blank=True, null=True) 
>
>
> I found some hints on the web about using get_form from my 
> RequestForChangeAdmin page, but it won't work because i get this error 
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
> search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
> date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>  def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>  print obj
> if obj.readiness == True:
> self.exclude = ("readinessDescription", )
> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
> return form
>

-- 
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/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: OneToOne? Inheritance? Another solution for nested model relationships?

2014-05-30 Thread Rafael E. Ferrero
2014-05-26 18:33 GMT-03:00 Daniele Procida :

> I've an application that's been happily running for a few years, that does
> this:
>
> class Person(Model):
># everyone's a Person
>
> class Researcher(Model):
> # a Researcher is Person who publishes research
> person = models.OneToOneField(Person)
>
> class Publication(Model):
> author = models.ForeignKey(Researcher)
>
>
> But this is no longer enough: now I also need to distinguish between
> Researchers who are research students and members of staff. Those who are
> students will need new fields such as "thesis_title" and "supervisors".
>
> But, I will *still* need the Researcher class independently of the new
> ResearchStudent and ResearchStaff classes, because it's needed for
> Publication.author.
>
> So now it might look something like this:
>
> class Person(Model):
># everyone's a Person
>
> class Researcher(Model):
> # a Researcher is Person who publishes research
> person = models.OneToOneField(Person)
>
> class ResearchStaff(Model):
>researcher = models.OneToOneField(Researcher)
>
> class ResearchStudent(Model):
>researcher = models.OneToOneField(Researcher)
>supervisors = models.ManyToManyField(ResearchStaff)
>
So, a ResearchStudent must be a Researcher and can have multiple
supervisors, but every supervisor must to be a ResearchStaff and a
Researcher too; and everyone is a Person here. Right?
Can a ResearchStudent be a ResearchStaff too?
i'll do something like this:


​



> class Publication(Model):
> author = models.ForeignKey(Researcher)
>
>
> How manageable is this going to be? Is there a better way of doing what I
> need to do, perhaps through inheritance?
>
> Thanks,
>
> Daniele
>
> --
> 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/20140526213320.1042853662%40mail.wservices.ch
> .
> 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/CAJJc_8U-FaX5PtQppji1kKrn259%2BtEwZCR9AdFqDUTecwdyJ_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
and one more thing. My obj is always none (empty), why is that?



On Friday, May 30, 2014 1:49:12 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hi,
>
>  
>
> Thanks for the response.
>
>  
>
> What do you mean by tri-state?
>
>  
>
> I changed my get_form to this:
>
> def get_form(self, request, obj=None, **kwargs):
>
>form = super(RequestForChangeAdmin, 
> self).get_form(request, obj, **kwargs)
>
>if obj:
>
>if obj.readiness == True:
>
>
> self.exclude = ("readinessDescription", )
>
>form = 
> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>
>return form
>
>  
>
> No my code run without errors, but nothing happpends though ☺
>
>  
>
> I have tried to change the readiness filds to yes and no, but the field 
> readiness descriptions is always displayed. Maybe it is not possibly to get 
> a fields attribute value from admin before the admin form is posted or 
> stored in database? Do you know?
>
>  
>
> Regards,
>
> Hilde from Norway
>
> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>
>> Hello,
>>
>> In my django admin page I want to hide some filelds from users if a 
>> special field value is set. I have tried different solutions to solve my 
>> problem but is stucked and hope someone can help me,
>>
>> If you look at my model I want to hide the field readinessDescription if 
>> readiness value is False (no), when the user log into admin page. 
>>
>> In model.py:
>> class RequestForChange (models.Model):
>> rfc = models.AutoField (primary_key=True, help_text="This is the grey 
>> text")
>> heading = models.CharField("Heading", max_length=50)
>>readiness = models.NullBooleanField("Readiness", blank=True, 
>> null=True)
>>readinessDescription = models.TextField("Description of 
>> readiness", max_length=250, blank=True, null=True) 
>>
>>
>> I found some hints on the web about using get_form from my 
>> RequestForChangeAdmin page, but it won't work because i get this error 
>> 'NoneType' object has no attribute 'readiness'
>>
>>
>> Here is what I have in admin.py:
>>
>> class RequestForChangeAdmin(admin.ModelAdmin):
>> formfield_overrides = {
>> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>> }
>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>> search_fields = ('changeId',)
>> list_filter = ('enviroment', 'acceptAT', 'status')
>> date_hierarchy = 'criticalDate'
>> inline = [RequestForChangeInline]
>>  def get_form(self, request, obj=None, **kwargs):
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>  print obj
>> if obj.readiness == True:
>> self.exclude = ("readinessDescription", )
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>> return form
>>
>

-- 
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/6896b357-475c-4c5a-bb56-fafd283b9ff3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
What do you mean by tri-state?

You are using a field that allows three states: TRUE, FALSE and NULL.

If I understand the model, readiness would either be TRUE or FALSE.  But if
you do not want to change your field type to:
readiness = models.BooleanField("Readiness", blank=True)

then try changing:
if obj.readiness == True:

to:

if obj.readiness and obj.readiness == True:

or just:
if obj.readiness:

Will give you the same result.

This way if it doesn't exist it will not fail on the  '== TRUE' test.



On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
wrote:

> Hi,
>
>
>
> Thanks for the response.
>
>
>
> What do you mean by tri-state?
>
>
>
> I changed my get_form to this:
>
> def get_form(self, request, obj=None, **kwargs):
>
>form = super(RequestForChangeAdmin,
> self).get_form(request, obj, **kwargs)
>
>if obj:
>
>if obj.readiness == True:
>
>
> self.exclude = ("readinessDescription", )
>
>form =
> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>
>return form
>
>
>
> No my code run without errors, but nothing happpends though ☺
>
>
>
> I have tried to change the readiness filds to yes and no, but the field
> readiness descriptions is always displayed. Maybe it is not possibly to get
> a fields attribute value from admin before the admin form is posted or
> stored in database? Do you know?
>
>
>
> Regards,
>
> Hilde from Norway
>
> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>
>> Hello,
>>
>> In my django admin page I want to hide some filelds from users if a
>> special field value is set. I have tried different solutions to solve my
>> problem but is stucked and hope someone can help me,
>>
>> If you look at my model I want to hide the field readinessDescription if
>> readiness value is False (no), when the user log into admin page.
>>
>> In model.py:
>> class RequestForChange (models.Model):
>> rfc = models.AutoField (primary_key=True, help_text="This is the grey
>> text")
>> heading = models.CharField("Heading", max_length=50)
>>readiness = models.NullBooleanField("Readiness", blank=True,
>> null=True)
>>readinessDescription = models.TextField("Description of
>> readiness", max_length=250, blank=True, null=True)
>>
>>
>> I found some hints on the web about using get_form from my
>> RequestForChangeAdmin page, but it won't work because i get this error
>> 'NoneType' object has no attribute 'readiness'
>>
>>
>> Here is what I have in admin.py:
>>
>> class RequestForChangeAdmin(admin.ModelAdmin):
>> formfield_overrides = {
>> models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>> }
>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>> search_fields = ('changeId',)
>> list_filter = ('enviroment', 'acceptAT', 'status')
>> date_hierarchy = 'criticalDate'
>> inline = [RequestForChangeInline]
>>  def get_form(self, request, obj=None, **kwargs):
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>  print obj
>> if obj.readiness == True:
>> self.exclude = ("readinessDescription", )
>> form = super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>> return form
>>
>  --
> 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/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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/CA%2B%3DOU3Xb87s3nHy%2BKPb_UEbVsSsrFd7Z5-OfisDKgN1gD6R6aQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
Maybe it is not possibly to get a fields attribute value from admin before
the admin form is posted or stored in database? Do you know?

Yes, it is possible.  I use this to set which fields are readonly before
defining the fieldsets.  It works great.


def get_form(self, request, obj=None, **kwargs):
try:
if obj.published:
self.readonly_fields =
['prj_name','published','lang','schema_code','description','sem_attr','resource_uri','asserts',

'label','performer_p','function','mode','simple_function','simple_mode',]
except (AttributeError, TypeError) as e:
self.readonly_fields = ['published','schema_code']
return super(ParticipationAdmin, self).get_form(request, obj,
**kwargs)






On Fri, May 30, 2014 at 9:05 AM, Timothy W. Cook  wrote:

> What do you mean by tri-state?
>
> You are using a field that allows three states: TRUE, FALSE and NULL.
>
> If I understand the model, readiness would either be TRUE or FALSE.  But
> if you do not want to change your field type to:
> readiness = models.BooleanField("Readiness", blank=True)
>
> then try changing:
> if obj.readiness == True:
>
> to:
>
> if obj.readiness and obj.readiness == True:
>
> or just:
> if obj.readiness:
>
> Will give you the same result.
>
> This way if it doesn't exist it will not fail on the  '== TRUE' test.
>
>
>
> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
> wrote:
>
>> Hi,
>>
>>
>>
>> Thanks for the response.
>>
>>
>>
>> What do you mean by tri-state?
>>
>>
>>
>> I changed my get_form to this:
>>
>> def get_form(self, request, obj=None, **kwargs):
>>
>>form = super(RequestForChangeAdmin,
>> self).get_form(request, obj, **kwargs)
>>
>>if obj:
>>
>>if obj.readiness == True:
>>
>>
>> self.exclude = ("readinessDescription", )
>>
>>form =
>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>
>>return form
>>
>>
>>
>> No my code run without errors, but nothing happpends though ☺
>>
>>
>>
>> I have tried to change the readiness filds to yes and no, but the field
>> readiness descriptions is always displayed. Maybe it is not possibly to get
>> a fields attribute value from admin before the admin form is posted or
>> stored in database? Do you know?
>>
>>
>>
>> Regards,
>>
>> Hilde from Norway
>>
>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>>
>>> Hello,
>>>
>>> In my django admin page I want to hide some filelds from users if a
>>> special field value is set. I have tried different solutions to solve my
>>> problem but is stucked and hope someone can help me,
>>>
>>> If you look at my model I want to hide the field readinessDescription if
>>> readiness value is False (no), when the user log into admin page.
>>>
>>> In model.py:
>>> class RequestForChange (models.Model):
>>>  rfc = models.AutoField (primary_key=True, help_text="This is the grey
>>> text")
>>> heading = models.CharField("Heading", max_length=50)
>>>readiness = models.NullBooleanField("Readiness", blank=True,
>>> null=True)
>>>readinessDescription = models.TextField("Description of
>>> readiness", max_length=250, blank=True, null=True)
>>>
>>>
>>> I found some hints on the web about using get_form from my
>>> RequestForChangeAdmin page, but it won't work because i get this error
>>> 'NoneType' object has no attribute 'readiness'
>>>
>>>
>>> Here is what I have in admin.py:
>>>
>>> class RequestForChangeAdmin(admin.ModelAdmin):
>>> formfield_overrides = {
>>>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>>> }
>>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>>>  search_fields = ('changeId',)
>>> list_filter = ('enviroment', 'acceptAT', 'status')
>>>  date_hierarchy = 'criticalDate'
>>> inline = [RequestForChangeInline]
>>>   def get_form(self, request, obj=None, **kwargs):
>>> form = super(RequestForChangeAdmin, self).get_form(request, obj,
>>> **kwargs)
>>>  print obj
>>> if obj.readiness == True:
>>> self.exclude = ("readinessDescription", )
>>>  form = super(RequestForChangeAdmin, self).get_form(request, obj,
>>> **kwargs)
>>> return form
>>>
>>  --
>> 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/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
>> 
>> .
>>
>> For more 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
Thanx,

I now changed my if test to just if obj.readines but then I get the error 
message 'NoneType' object has no attribute 'readiness'


I have tried with several fields from my model, but I always get this 
error. I guess it must be something essential I am doing wrong here, since 
my obj seems to be none always...

I have get_form inside my modelAdmin class.


On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>
> What do you mean by tri-state?
>
> You are using a field that allows three states: TRUE, FALSE and NULL. 
>
> If I understand the model, readiness would either be TRUE or FALSE.  But 
> if you do not want to change your field type to:
> readiness = models.BooleanField("Readiness", blank=True)
>  
> then try changing:
> if obj.readiness == True:
>
> to:
>
> if obj.readiness and obj.readiness == True:
>
> or just:
> if obj.readiness:
>
> Will give you the same result.
>
> This way if it doesn't exist it will not fail on the  '== TRUE' test. 
>
>
>
> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen  > wrote:
>
>> Hi,
>>
>>  
>>
>> Thanks for the response.
>>
>>  
>>
>> What do you mean by tri-state?
>>
>>  
>>
>> I changed my get_form to this:
>>
>> def get_form(self, request, obj=None, **kwargs):
>>
>>form = super(RequestForChangeAdmin, 
>> self).get_form(request, obj, **kwargs)
>>
>>if obj:
>>
>>if obj.readiness == True:
>>
>>
>> self.exclude = ("readinessDescription", )
>>
>>form = 
>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>
>>return form
>>
>>  
>>
>> No my code run without errors, but nothing happpends though ☺
>>
>>  
>>
>> I have tried to change the readiness filds to yes and no, but the field 
>> readiness descriptions is always displayed. Maybe it is not possibly to get 
>> a fields attribute value from admin before the admin form is posted or 
>> stored in database? Do you know?
>>
>>  
>>
>> Regards,
>>
>> Hilde from Norway
>>
>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>>>
>>> Hello,
>>>
>>> In my django admin page I want to hide some filelds from users if a 
>>> special field value is set. I have tried different solutions to solve my 
>>> problem but is stucked and hope someone can help me,
>>>
>>> If you look at my model I want to hide the field readinessDescription if 
>>> readiness value is False (no), when the user log into admin page. 
>>>
>>> In model.py:
>>> class RequestForChange (models.Model):
>>>  rfc = models.AutoField (primary_key=True, help_text="This is the grey 
>>> text")
>>> heading = models.CharField("Heading", max_length=50)
>>>readiness = models.NullBooleanField("Readiness", blank=True, 
>>> null=True)
>>>readinessDescription = models.TextField("Description of 
>>> readiness", max_length=250, blank=True, null=True) 
>>>
>>>
>>> I found some hints on the web about using get_form from my 
>>> RequestForChangeAdmin page, but it won't work because i get this error 
>>> 'NoneType' object has no attribute 'readiness'
>>>
>>>
>>> Here is what I have in admin.py:
>>>
>>> class RequestForChangeAdmin(admin.ModelAdmin):
>>> formfield_overrides = {
>>>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
>>> }
>>> list_display = ('rfc', 'heading', 'enviroment', 'status')
>>>  search_fields = ('changeId',)
>>> list_filter = ('enviroment', 'acceptAT', 'status')
>>>  date_hierarchy = 'criticalDate'
>>> inline = [RequestForChangeInline]
>>>   def get_form(self, request, obj=None, **kwargs):
>>> form = super(RequestForChangeAdmin, self).get_form(request, obj, 
>>> **kwargs)
>>>  print obj
>>> if obj.readiness == True:
>>> self.exclude = ("readinessDescription", )
>>>  form = super(RequestForChangeAdmin, self).get_form(request, obj, 
>>> **kwargs)
>>> return form
>>>
>>  -- 
>> 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/5bc768df-3a1c-4b53--2ec19b9c05f0%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> 
> Timothy Cook
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> MLHIM http://www.mlhim.org
>
> 

-- 
You received this message because you are s

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
I have uploaded my model and admin file and hope someone can tell me why I 
can't get my get_form method to work :)

Regards,
Hilde

>
>>  

-- 
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/494dcd61-e77f-4844-8243-d838169bea5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.db import models
from django.contrib.auth.models import User
from django.forms import CheckboxSelectMultiple
from django.contrib import admin



class Enviroment (models.Model):
	enviroment = models.AutoField (primary_key=True)
	EnviromentName = models.CharField("Enviroment", max_length = 50)
	def __unicode__(self):
		return '%s' % (self.EnviromentName)

class ChangeType (models.Model):
	change = models.AutoField (primary_key=True)
	changeName = models.CharField(verbose_name="Type of change", max_length = 50)
	
	def __unicode__(self):
		return '%s' % (self.changeName)

	
class Status (models.Model):
	status = models.AutoField (primary_key=True)
	statusName = models.CharField("Status", max_length = 50)
	def __unicode__(self):
		return '%s' % (self.statusName)

class Resource (models.Model):
	resource = models.AutoField (primary_key=True)
	resourceFirstName = models.CharField("First name", max_length = 50)
	resourceLastName = models.CharField("Last name", max_length = 50)
	organization = models.CharField("Organization", max_length = 50)
	resourcePhone = models.IntegerField("Phone number")
	resourceRole = models.CharField("Role", max_length=50)
	def __unicode__(self):
		return '%s %s' % (self.resourceFirstName, self.resourceLastName)

class ReasonForChange(models.Model):
	reasonForChange = models.AutoField (primary_key=True)
	reasonForChangeName = models.CharField("Reason for change", max_length=50)
	def __unicode__(self):
		return '%s' % (self.reasonForChangeName)
		
class GoalOfChange (models.Model):
	goalOfChange = models.AutoField(primary_key=True)
	goalOfChangeName = models.CharField("Goal of change", max_length=50)
	def __unicode__(self):
		return '%s' % (self.goalOfChangeName)
	
	
class RequestForChange (models.Model):
	formfield_overrides  = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
	One = '1'
	Two = '2'
	Three = '3'
	Four = '4'
	EFFECT_CHOICES = (
		(One, '1'),
		(Two, '2'),
		(Three, '3'),
		(Four, '4'),
)
	rfc = models.AutoField (primary_key=True, help_text="This is the grey text")
	user = models.ForeignKey(User, verbose_name="Change owner")
	changeId = models.IntegerField("Frontrange ID", blank=True, null=True)
	TFSId = models.IntegerField("TFS ID", blank=True, null=True)
	enviroment = models.ForeignKey(Enviroment, verbose_name="Enviroment")
	status = models.ForeignKey(Status, verbose_name="Status")
	heading = models.CharField("Heading", max_length=50)
	reasonForChange = models.ManyToManyField(ReasonForChange, verbose_name="Reason for change", blank=True, null=True)
	reasonForChange = models.ManyToManyField(ReasonForChange, verbose_name="Reason for change", blank=True, null=True)
	goalOfChange = models.ManyToManyField(GoalOfChange, verbose_name="Goal of change test",blank=True, null=True )
	rfcDateCreated = models.DateField("Date created")
	acceptAT = models.NullBooleanField("Is the change accepted by customer?", blank=True, null=True)
	testReport = models.NullBooleanField("Do we have a testreport?", blank=True, null=True)
	critical = models.NullBooleanField("Time critical", blank=True, null=True)
	criticalDate = models.DateField("Critical date", blank=True, null=True)
	CriticalDateDescription = models.TextField("Description", max_length=250, blank=True, null=True)
	effect = models.CharField(choices=EFFECT_CHOICES, verbose_name="Effect", max_length=2, blank=True, null=True)
	urgency = models.CharField(choices=EFFECT_CHOICES, verbose_name="Effect", max_length=2, blank=True, null=True)
	priority = models.IntegerField("Priority", blank=True, null=True)
	priorityComments = models.TextField("Comments", max_length=100, blank=True, null=True)
	budget = models.TextField("Description of budget", max_length=250, blank=True, null=True)
	estimatedTime = models.CharField("Estimated time for deploy of change", max_length=30, blank=True, null=True)
	changeType = models.ForeignKey(ChangeType, verbose_name="Type of change")
	resource = models.ManyToManyField(Resource, verbose_name="Responsible for change?", blank=True, null=True)
	stakeholder = models.ManyToManyField(Resource, related_name='stakeholder', verbose_name="Stakeholders", blank=True, null=True)
	effectOnEnviroments = models.ManyToManyField(Enviroment, related_name="EffectOnEnviroment", verbose_name="Enviroment thi

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Timothy W. Cook
try this get_form:

def get_form(self, request, obj=None, **kwargs):
if obj.readiness:
self.exclude = ("readinessDescription", )
return super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)


I have never used 'exclude' but it looks like yours should work.


On Fri, May 30, 2014 at 9:18 AM, Hilde Rafaelsen 
wrote:

> Thanx,
>
> I now changed my if test to just if obj.readines but then I get the error
> message 'NoneType' object has no attribute 'readiness'
>
>
> I have tried with several fields from my model, but I always get this
> error. I guess it must be something essential I am doing wrong here, since
> my obj seems to be none always...
>
> I have get_form inside my modelAdmin class.
>
>
> On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>
>> What do you mean by tri-state?
>>
>> You are using a field that allows three states: TRUE, FALSE and NULL.
>>
>> If I understand the model, readiness would either be TRUE or FALSE.  But
>> if you do not want to change your field type to:
>> readiness = models.BooleanField("Readiness", blank=True)
>>
>> then try changing:
>> if obj.readiness == True:
>>
>> to:
>>
>> if obj.readiness and obj.readiness == True:
>>
>> or just:
>> if obj.readiness:
>>
>> Will give you the same result.
>>
>> This way if it doesn't exist it will not fail on the  '== TRUE' test.
>>
>>
>>
>> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen 
>> wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>> Thanks for the response.
>>>
>>>
>>>
>>> What do you mean by tri-state?
>>>
>>>
>>>
>>> I changed my get_form to this:
>>>
>>> def get_form(self, request, obj=None, **kwargs):
>>>
>>>form = super(RequestForChangeAdmin,
>>> self).get_form(request, obj, **kwargs)
>>>
>>>if obj:
>>>
>>>if obj.readiness == True:
>>>
>>>
>>> self.exclude = ("readinessDescription", )
>>>
>>>form =
>>> super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)
>>>
>>>return form
>>>
>>>
>>>
>>> No my code run without errors, but nothing happpends though ☺
>>>
>>>
>>>
>>> I have tried to change the readiness filds to yes and no, but the field
>>> readiness descriptions is always displayed. Maybe it is not possibly to get
>>> a fields attribute value from admin before the admin form is posted or
>>> stored in database? Do you know?
>>>
>>>
>>>
>>> Regards,
>>>
>>> Hilde from Norway
>>>
>>> On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:

 Hello,

 In my django admin page I want to hide some filelds from users if a
 special field value is set. I have tried different solutions to solve my
 problem but is stucked and hope someone can help me,

 If you look at my model I want to hide the field readinessDescription
 if readiness value is False (no), when the user log into admin page.

 In model.py:
 class RequestForChange (models.Model):
  rfc = models.AutoField (primary_key=True, help_text="This is the grey
 text")
 heading = models.CharField("Heading", max_length=50)
readiness = models.NullBooleanField("Readiness", blank=True,
 null=True)
readinessDescription = models.TextField("Description of
 readiness", max_length=250, blank=True, null=True)


 I found some hints on the web about using get_form from my
 RequestForChangeAdmin page, but it won't work because i get this error
 'NoneType' object has no attribute 'readiness'


 Here is what I have in admin.py:

 class RequestForChangeAdmin(admin.ModelAdmin):
 formfield_overrides = {
  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
 }
 list_display = ('rfc', 'heading', 'enviroment', 'status')
  search_fields = ('changeId',)
 list_filter = ('enviroment', 'acceptAT', 'status')
  date_hierarchy = 'criticalDate'
 inline = [RequestForChangeInline]
   def get_form(self, request, obj=None, **kwargs):
 form = super(RequestForChangeAdmin, self).get_form(request, obj,
 **kwargs)
  print obj
 if obj.readiness == True:
 self.exclude = ("readinessDescription", )
  form = super(RequestForChangeAdmin, self).get_form(request, obj,
 **kwargs)
 return form

>>>  --
>>> 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/5bc768df-3a1c-4b53--2ec19b9c05f0%
>>> 40googlegroups.com
>>> 

Re: Problem hiding fields from admin page based on another fields value

2014-05-30 Thread Hilde Rafaelsen
I get same error as before; 'NoneType' object has no attribute 'readiness' 
when I changed to your excample. I don't understand why this is not working 
for me, but for everyone else

Is it something I have forgot to import? I hope you can take a quick look 
at my uploaded files. Is it ok to just use get_form from the admin class 
directly, or do I need to create a Form class as well?



On Friday, May 30, 2014 2:35:01 PM UTC+2, Timothy W. Cook wrote:
>
> try this get_form:
>
> def get_form(self, request, obj=None, **kwargs):
>  if obj.readiness:
>  self.exclude = ("readinessDescription", )
>  return super(RequestForChangeAdmin, self).get_form(request, obj, 
> **kwargs)
>
>
> I have never used 'exclude' but it looks like yours should work. 
>
>
> On Fri, May 30, 2014 at 9:18 AM, Hilde Rafaelsen  > wrote:
>
>> Thanx,
>>
>> I now changed my if test to just if obj.readines but then I get the error 
>> message 'NoneType' object has no attribute 'readiness'
>>
>>
>> I have tried with several fields from my model, but I always get this 
>> error. I guess it must be something essential I am doing wrong here, since 
>> my obj seems to be none always...
>>
>> I have get_form inside my modelAdmin class.
>>
>>
>> On Friday, May 30, 2014 2:06:59 PM UTC+2, Timothy W. Cook wrote:
>>
>>> What do you mean by tri-state?
>>>
>>> You are using a field that allows three states: TRUE, FALSE and NULL. 
>>>
>>> If I understand the model, readiness would either be TRUE or FALSE.  But 
>>> if you do not want to change your field type to:
>>> readiness = models.BooleanField("Readiness", blank=True)
>>>  
>>> then try changing:
>>> if obj.readiness == True:
>>>
>>> to:
>>>
>>> if obj.readiness and obj.readiness == True:
>>>
>>> or just:
>>> if obj.readiness:
>>>
>>> Will give you the same result.
>>>
>>> This way if it doesn't exist it will not fail on the  '== TRUE' test. 
>>>
>>>  
>>>
>>> On Fri, May 30, 2014 at 8:49 AM, Hilde Rafaelsen  
>>> wrote:
>>>
  Hi,

  

 Thanks for the response.

  

 What do you mean by tri-state?

  

 I changed my get_form to this:

 def get_form(self, request, obj=None, **kwargs):

form = super(RequestForChangeAdmin, 
 self).get_form(request, obj, **kwargs)

if obj:

if obj.readiness == 
 True:


 self.exclude = ("readinessDescription", )

form = 
 super(RequestForChangeAdmin, self).get_form(request, obj, **kwargs)

return form

  

 No my code run without errors, but nothing happpends though ☺

  

 I have tried to change the readiness filds to yes and no, but the field 
 readiness descriptions is always displayed. Maybe it is not possibly to 
 get 
 a fields attribute value from admin before the admin form is posted or 
 stored in database? Do you know?

  

 Regards,

 Hilde from Norway

 On Friday, May 30, 2014 12:57:19 PM UTC+2, Hilde Rafaelsen wrote:
>
> Hello,
>
> In my django admin page I want to hide some filelds from users if a 
> special field value is set. I have tried different solutions to solve my 
> problem but is stucked and hope someone can help me,
>
> If you look at my model I want to hide the field readinessDescription 
> if readiness value is False (no), when the user log into admin page. 
>
> In model.py:
> class RequestForChange (models.Model):
>  rfc = models.AutoField (primary_key=True, help_text="This is the 
> grey text")
> heading = models.CharField("Heading", max_length=50)
>readiness = models.NullBooleanField("Readiness", blank=True, 
> null=True)
>readinessDescription = models.TextField("Description of 
> readiness", max_length=250, blank=True, null=True) 
>
>
> I found some hints on the web about using get_form from my 
> RequestForChangeAdmin page, but it won't work because i get this error 
> 'NoneType' object has no attribute 'readiness'
>
>
> Here is what I have in admin.py:
>
> class RequestForChangeAdmin(admin.ModelAdmin):
> formfield_overrides = {
>  models.ManyToManyField: {'widget': CheckboxSelectMultiple},
> }
> list_display = ('rfc', 'heading', 'enviroment', 'status')
>  search_fields = ('changeId',)
> list_filter = ('enviroment', 'acceptAT', 'status')
>  date_hierarchy = 'criticalDate'
> inline = [RequestForChangeInline]
>   def get_form(self, request, obj=None, **kwargs):
> form = super(RequestForChangeAdmin, self).get_form(request, obj, 
> **kwargs)
>  print obj
> if obj.readiness == True:
> self.

Seems to be a bug in makemessages management command

2014-05-30 Thread Андрей Меньков
Django management command doesn't recognize multiline strings as strings to
localize. So such strings don't appear in resulting django.po files after
running command

For example for such a string

{code}
{{ _(''' fhsdafjkshdfjkasdhfksj
 ytyerwtuiwyertuiywert''') }}
{code}

I might be the bug of GNU xgettext utility, because makemessages uses it to
produce *.po files, but after running xgettext I became sure that the
problem is in the makemessages command, not xgettext.

I ran xgettext using the following command

xgettext --keyword=gettext_noop --keyword=gettext_lazy
--keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy
--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2
--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2
--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8
--add-comments=Translators --from-code utf-8 -d django -p ./output_dir -L
Python temp_i18n_template.html

After running this command I got file output_dir/django.po with specified
string inside it.

What I can do now? What do you think about this "bug" ?

P.S. It's my first attempt to contribute to Django somehow. So please do
not judge strictly). I haven't found anywhere about this problem and about
its' fixes too.

-- 
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/CAL40Fpvq5K_GP0k1oXuUVHH8-UCeCcFDMVJ2F9QWp6RUNRkSzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: backbonejs and django

2014-05-30 Thread Eddilbert Macharia
Hi sanjay,

Thanks for your reply,here is how I did it this way

$(function(){
// event object
var vent=_.extend({},Backbone.Events)

// the model
var myModel=Backbone.Model.extend();

// the model collection
var myModelCollection=Backbone.Collection.extend({
model:myModel,
urlRoot: 'resp',
initialize:function(){
this.fetch({
success:function(){
vent.trigger('fetched')
}
})
},
});

// one model view
var myModelView=Backbone.View.extend({
tagName:'p', 
template:_.template($('#demotpl').html()),
initialize:function(){
//this.render()
},
render:function(){
this.$el.html(this.template(this.model.toJSON()));
return this;
},
});


// model collection view
var myModelCollectionView=Backbone.View.extend({
el:'.demo', 
initialize:function(){
vent.on('fetched',this.render,this)
//this.render()
},
render:function(){
this.collection.each(this.one,this)
},
one:function(onemod){
var onemodView=new myModelView({model:onemod})
console.log(onemod)
this.$el.append(onemodView.render().el)
}
});

// initialize the collection
var newCollection=new myModelCollection()

// initaliaze collection view
var newCollectionView=new 
myModelCollectionView({collection:newCollection})
});


is there another way i could have done it?

-- 
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/b812a380-47a6-40b6-b581-d00b6955f75b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems to be a bug in makemessages management command

2014-05-30 Thread Андрей Меньков
May be it would better to post this to "Django developers" mailing list?

пятница, 30 мая 2014 г., 15:53:56 UTC+3 пользователь Андрей Меньков написал:
>
> Django management command doesn't recognize multiline strings as strings 
> to localize. So such strings don't appear in resulting django.po files 
> after running command
>
> For example for such a string
>
> {code}
> {{ _(''' fhsdafjkshdfjkasdhfksj
>  ytyerwtuiwyertuiywert''') }}
> {code}
>
> I might be the bug of GNU xgettext utility, because makemessages uses it 
> to produce *.po files, but after running xgettext I became sure that the 
> problem is in the makemessages command, not xgettext.
>
> I ran xgettext using the following command
>
> xgettext --keyword=gettext_noop --keyword=gettext_lazy 
> --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy 
> --keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 
> --keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 
> --keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 
> --add-comments=Translators --from-code utf-8 -d django -p ./output_dir -L 
> Python temp_i18n_template.html
>
> After running this command I got file output_dir/django.po with specified 
> string inside it.
>
> What I can do now? What do you think about this "bug" ?
>
> P.S. It's my first attempt to contribute to Django somehow. So please do 
> not judge strictly). I haven't found anywhere about this problem and about 
> its' fixes too.
>

-- 
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/565e7448-bdc8-4b60-8f59-ab8d13d2eb34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


check_password in contrib auth tries to update the database

2014-05-30 Thread suhridsatyal
Hi,

I am getting this error 

> cannot execute UPDATE in a read-only transaction

from a method in auth module that supposedly checks for password.

check_password method of AbstractBaseUser in django.contrib.auth.models 
tries to update the database. 
This causes problems when this code executes on a read-only slave database.

Here is the source code of the method:

def check_password(self, raw_password):
> """
> Returns a boolean of whether the raw_password was correct. Handles
> hashing formats behind the scenes.
> """
> def setter(raw_password):
> self.set_password(raw_password)
> self.save(update_fields=["password"])
> return check_password(raw_password, self.password, setter)



Has anyone come across this issue before? 

--
Suhrid

-- 
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/f754fc33-fd4c-4653-bf6f-ddffa58542e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Registration extend nightmare

2014-05-30 Thread Matt Guy
I am trying to add an extra user profile registration field using 
registration. Should be so simple but this is bringing me to the edge.

Here's my stackoverflow question with 
bounty: 
https://stackoverflow.com/questions/23695713/django-reg-extend-current-transaction-is-aborted-commands-ignored-until-end-o


Basically I want to add a '*city*' field to the registration form. I have 
tried many solutions, but am currently attempting versions of this: 
http://dmitko.ru/django-registration-form-custom-field/

In my app I have a backend *regbackend.py *relying on django-registration's 
signals:

__

from forms import *
from models import UserProfile
from django.db.models.signals import post_save


def user_created(sender, user, request, **kwargs):
new_user = RegistrationProfile.objects.get(us)
form = CustomRegistrationForm(request.POST)
data = UserProfile(user=user)
import ipdb; ipdb.set_trace();
data.locality = form.data["locality"]
data.save()

from registration.signals import user_registered
import crewcal.models
user_registered.connect(user_created)
__


The related models:

__

class Locality(models.Model):
locality = models.CharField(max_length=50)

def __unicode__(self):
return self.locality

class UserProfile(models.Model):
user = models.OneToOneField(User)
event_commitments = models.ManyToManyField(Event,
null=True, blank=True)
receive_email = models.BooleanField(default=True)
locality = models.ManyToManyField(Locality,
null=True, blank=True)

def __unicode__(self):
return self.user.username

@property
def url(self):
return self.get_absolute_url()

@models.permalink
def get_absolute_url(self):
return ('crewcal.views.profile', [str(self.id)])

userprofile_created = django.dispatch.Signal(providing_args=["user", 
"request"])

def create_user_profile(sender, instance, created, raw, **kwargs):
if created and not raw:
UserProfile.objects.create(user=instance)
profile = UserProfile.objects.get(user=instance)
userprofile_created.send(sender=UserProfile,
user=instance, request=request)

post_save.connect(create_user_profile, sender=User)

User.profile = property(lambda u: UserProfile.\
 objects.get_or_create(user=u)[0])
__


I get a mixture of errors (dependent on the slight tweaks I make), such as:

current transaction is aborted, commands ignored until end of transaction 
block

and:

"" needs to have a value for field "userprofile" before 
this many-to-many relationship can be used.


This last message suggests to me that the UserProfile is not saved before the 
signal is sent (from the *django-registration* plugin) to the custom backend 
(*regbackend.py* above) which attempts to update that non-existent entry with 
the locality. Here is the relevant code from *django-registration views.py:*

__

def register(self, request, **cleaned_data):

"""

Given a username, email address and password, register a new

user account, which will initially be inactive.


Along with the new ``User`` object, a new

``registration.models.RegistrationProfile`` will be created,

tied to that ``User``, containing the activation key which

will be used for this account.

After the ``User`` and ``RegistrationProfile`` are created and the 
activation email is sent, the signal

``registration.signals.user_registered`` will be sent, with

the new ``User`` as the keyword argument ``user`` and the

class of this backend as the sender.

"""

username, email, password = cleaned_data['username'], 
cleaned_data['email'], cleaned_data['password1']

if Site._meta.installed:

site = Site.objects.get_current()

else:

site = RequestSite(request)

new_user = RegistrationProfile.objects.create_inactive_user(username, 
email, password, site)

signals.user_registered.send(sender=self.__class__,

 user=new_user,

 request=request)

return new_user

__

and from models.py:


__

def create_inactive_user(self, username, email, password,

 site, send_email=True):

"""

Create a new, inactive ``User``, generate a

``RegistrationProfile`` and email its activation key to the

``User``, returning the new ``User``.

By default, an activation email will be sent to the new

user. To disable this, pass ``send_email=False``.

"""

new_user = User.objects.create_user(us

Fwd: Django Template - problema

2014-05-30 Thread Erick Brockes
I have the following problem. The field "tipo_conjuge" is not showing as I
wanted. Could somebody tell me what is the problem?

Best regards,
Erick


url. py

...
url(r'relacao/(?P\d+)/$',
login_required(CreateTipoRelacaoView.as_view()),
name='cadastrarRelacaoTipo'),
...


views.py

...
class CreateTipoRelacaoView(CreateView):
model = RelacaoConjugeTipoUniao
fields = ['tipo_conjuge','data_inicio','data_fim']

def form_valid(self, form):
relacao = get_object_or_404(RelacaoConjuge,
id=self.kwargs['relacao'])
form.instance.relacao = relacao
return super(CreateTipoRelacaoView, self).form_valid(form)


models.py

class RelacaoConjugeTipoUniao(models.Model):

TIPO_CONJUGE = (
('CA', _('Casados')),
('UE', _('União estável')),
('OU', _('Outros')),
)

tipo_conjuge = models.CharField(_('Tipo'), max_length=2,
choices=TIPO_CONJUGE, blank=False, null=False)
data_inicio = models.DateField(_('Data de início'))
data_fim = models.DateField(_('Data de término'))
   ...


relacaoconjugetipouniao_form.html

{% extends 'pessoa/base_voltar.html' %}
{% block content %}
{% csrf_token %}
{{ form.non_field_errors }}

{{ form.tipo_conjuge.errors }}
Tipo de União:
{{ form.tipo_conjuge }}


{{ form.data_inicio.errors }}
Data de início:
{{ form.data_inicio }}


{{ form.data_fim.errors }}
Data de término:
{{ form.data_fim }}





Voltar
{% endblock content %}

-- 
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/CALUDr%2B0e1ZfcuLZRsHWcOR5L-LiS%3DqLPw-bWv6-SqCHqTrFBPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


makemessages doesn't understand I'm reusing Django existing translation messages

2014-05-30 Thread Selenite Vingt-Neuf
Hi,

I'm writing authentication templates using authentication views provided by 
Django, and for that purpose I am reusing translation messages present in 
django.contrib.admin.

That works very well at the execution time, Django understands that 
translation messages already exist in django.contrib.admin and display them 
in the requested language (French in my case).

My concern is that "django-admin.py makemessages -a" command doesn't 
understand just as well and it creates those translation messages again in 
my auth app's locale files. But I don't need them, or at least commented as 
#fuzzy. Is it the normal behavior of that command or am I doing wrong ?

Below is the example with the message "Reset my password":

In django.contrib.admin locale files:

- 
path/to/python2.7/sites-packages/django/contrib/admin/locale/en/LC_MESSAGES/django.py

#: templates/registration/password_reset_form.html:21
msgid "Reset my password"
msgstr ""

 
- 
path/to/python2.7/sites-packages/django/contrib/admin/locale/fr/LC_MESSAGES/django.py

#: templates/registration/password_reset_form.html:21
msgid "Reset my password"
msgstr "Réinitialiser mon mot de passe"


In my password_reset template of my auth app:

- auth/templates/auth/password_reset.html:

*{% load i18n %}*





In my auth app's locale files after typing "cd path/to/myproject; cd auth; 
django-admin.py makemessages -a":

- auth/locale/en/LC_MESSAGES/django.po:

#: templates/auth/password_reset.html:36
msgid "Reset my password"
msgstr ""


- auth/locale/en/LC_MESSAGES/django.po:

#: templates/auth/password_reset.html:36
msgid "Reset my password"
msgstr ""


Here my settings:

- myproject/settings.py:


MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)

LANGUAGE_CODE = 'en-us'

LANGUAGES = (
('fr', _('French')),
('en', _('English')),
)

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


Here my config:

- Mac OS X 10.9.2
- python 2.7.6
- gettext 0.18.3 (installed via homebrew)

Thanks for your help.

Cheers,

Selenite Vingt-Neuf

-- 
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/d95b17f0-650d-4bc6-8209-ab38fb6ca34e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Template - problema

2014-05-30 Thread Kelvin Wong
In relacaoconjugetipouniao_form.html

Add this tag...then refresh...

{{ form.fields }}

Should give you more info about what fields are in the form and what widget 
they are using.

ie. 'tipo_conjuge': django.forms.fields.TypedChoiceField object

Also check your html source in a browser. Sometimes CSS mistakes hide 
things.

K


On Friday, May 30, 2014 7:40:01 AM UTC-7, ebrockes wrote:
>
> I have the following problem. The field "tipo_conjuge" is not showing as I 
> wanted. Could somebody tell me what is the problem? 
>
> Best regards,
> Erick
>
>
> url. py
>
> ...
> url(r'relacao/(?P\d+)/$', 
> login_required(CreateTipoRelacaoView.as_view()), 
> name='cadastrarRelacaoTipo'),
> ...
>
>
> views.py
>
> ...
> class CreateTipoRelacaoView(CreateView):
> model = RelacaoConjugeTipoUniao
> fields = ['tipo_conjuge','data_inicio','data_fim']
>
> def form_valid(self, form):
> relacao = get_object_or_404(RelacaoConjuge, 
> id=self.kwargs['relacao'])
> form.instance.relacao = relacao
> return super(CreateTipoRelacaoView, self).form_valid(form)
>
>
> models.py
>
> class RelacaoConjugeTipoUniao(models.Model):
>
> TIPO_CONJUGE = (
> ('CA', _('Casados')),
> ('UE', _('União estável')),
> ('OU', _('Outros')),
> )
>
> tipo_conjuge = models.CharField(_('Tipo'), max_length=2, 
> choices=TIPO_CONJUGE, blank=False, null=False)
> data_inicio = models.DateField(_('Data de início'))
> data_fim = models.DateField(_('Data de término'))
>...
>
>
> relacaoconjugetipouniao_form.html
>
> {% extends 'pessoa/base_voltar.html' %}
> {% block content %}
> {% csrf_token %}
> {{ form.non_field_errors }}
> 
> {{ form.tipo_conjuge.errors }}
> Tipo de União:
> {{ form.tipo_conjuge }}
> 
> 
> {{ form.data_inicio.errors }}
> Data de início:
> {{ form.data_inicio }}
> 
> 
> {{ form.data_fim.errors }}
> Data de término:
> {{ form.data_fim }}
> 
> 
> 
> 
> 
> Voltar
> {% endblock content %}
>  
>

-- 
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/2c343d4f-48e4-4e5a-a02f-137edc1b0de2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Suggestions for Paginating a Growing Django Queryset

2014-05-30 Thread Riegie Godwin
Hello everyone!
 
  I've been stuck for about a week trying to figure this out. Been on 
all sorts of blogs and asked questions on stackoverflow in hopes that it 
would lead in the right direction. I would like to know what you think I 
could do.
 
Let's say I have 4 models, a User model, Blog Model, Hashtag and a Comment 
model. Users can create blogs, users can comment on them and blogs can be 
tagged by the blog owner from the comments or the blog description itself. 
If I we're to best describe this, think of Instagram. You can hashtag your 
photo when your uploading it, and afterwards by commenting on it. 
 
Here are the models:
 
#models.py
 
from django.db import models
from django.contrib.auth.models import User
 
class Blog(models.Model):
   user = models.ForeignKey(User)
   description = models.CharField(max_length=140, blank=True)
   blog_text = models.CharField(max_length=5000,  blank=True)
   related_hashtags = models.ManyToManyField('Hashtag', 
related_name = 'tagged_post', null=True, blank=True)
 
 
class Comment(models.Model):
   user = models.ForeignKey(User)
   comment = models.CharField(max_length=140, blank=True)
 
class Hashtag(models.Model):
   user = models.ForeignKey(User)
   comment = models.CharField(max_length=140, blank=True)
   count = models.IntegerField(default=1)
 
Pretty simple. A blog can have multiple hashtags and a hashtag can belong 
to multiple blogs. When a user creates a blog, I check the description 
string for any hashtags using the following function below:
 
 hash_tags = re.findall(r'#(\w+)', blog.description, re.UNICODE)[:30] # 
each blog can have a maximum of 30 hashtags
 if hash_tags:
for hash_tag in hash_tags:
   try:
  oldHashtag = 
Hashtag.objects.get(hashtag = hash_tag)
  oldHashtag.count = 
oldHashtag.count + 1
  oldHashtag.save()
  
blog.related_hashtag.add(oldHashtag)

   except Hashtag.DoesNotExist:
   newHashtag = 
Hashtag.objects.create(hashtag = lowercase_hash_tag)
  
 blog.related_hashtag.add(newHashtag)

I hope so far everything makes sense. I do the same as above whenever a 
Comment object is created.

Now let's imagine the hashtag #acdc is really popular, about 20-40 blogs 
are added to that hashtag about every millisecond.

If the user searches for #acdc, I would like to show the latest 20 blogs 
that have just been added with #acdc, and as the user loads more, I'll show 
the next 20. They are ordered in DESC order of insertion.

I had to resort to RAW SQL since Django couldn't order the queryset by the 
pk of the ManyToManyField, many others suggested using a through table, but 
for legacy reasons, I did it this way:

SELECT * FROM django_blog INNER JOIN django_blog_related_hashtag ON ( 
django_blog.id = django_blog_related_hashtag.blog_id ) INNER JOIN 
django_hashtag ON ( django_blog_related_hashtag.hashtag_id = 
django_hashtag.id ) WHERE ( django_hashtag.hashtag = 'acdc' ) ORDER BY 
django_blog_related_hashtag.id DESC LIMIT 20

If the user wanted to view page two, I'd simply add an OFFSET at the end of 
the query. A simple function like so:

OFFSET = (page_number -1) * 20

This all works great, but for web apps like Instagram or Twitter or this 
Blog app I just made, if the queryset is constantly growing, the user is 
not always in sync with the most recent data. Which is perfectly fine, I 
don't care about that. But what I do care about is that the next page that 
they request must contain the results that are suppose to come after the 
ones they have just received. If I don't account for this, users might see 
blogs that they have already seen from previous pages because of the 
growing queryset. Someone mentioned caching the entire queryset, but 
wouldn't that have a large memory over head?

I'm looking forward to hearing your thoughts and suggestions.

Kind Regards,

Riegie Godwin

-- 
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/c9dace38-4cde-4462-98bb-3ff689b14c7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Registration extend nightmare

2014-05-30 Thread Kelvin Wong
This is not an answer to your question, but I have used Django-registration 
before and ran into its limitations. Consider all the time you spent trying 
to debug this then consider that you'd probably already be done if you had 
just wrote a custom user and maybe salvaged some of the nicer code 
from Django-registration.

I've seen that error before. I seem to recall it comes from the way 
postgres handles transactions when one part of the transaction craps out. 
You might find some good info if you search for that specific message with 
the term postgres. Maybe also review the docs on Django transactions.

https://docs.djangoproject.com/en/1.6/topics/db/transactions/

K


On Friday, May 30, 2014 7:26:04 AM UTC-7, Matt Guy wrote:
>
> I am trying to add an extra user profile registration field using 
> registration. Should be so simple but this is bringing me to the edge.
>

-- 
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/c52d14c1-17ef-4d6b-98d2-0670b7676da7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: makemessages doesn't understand I'm reusing Django existing translation messages

2014-05-30 Thread visionary800
My recent experience with using django-admin.py makemessages is that this 
command only works when there is a subdirectory present named 'locale' that 
sits just below where you are executing this command.  Without a 'locale' 
subdirectory present, the command will raise an error.  I think by design 
it only makes translation files for the user created project/apps.  You can 
exclude parts of your project.

http://stackoverflow.com/questions/9973584/django-admin-makemessages-translate-all-django-package-with-mine

I am not sure if that helped.


On Friday, May 30, 2014 9:57:40 AM UTC-7, Selenite Vingt-Neuf wrote:
>
> Hi,
>
> I'm writing authentication templates using authentication views provided 
> by Django, and for that purpose I am reusing translation messages present 
> in django.contrib.admin.
>
> That works very well at the execution time, Django understands that 
> translation messages already exist in django.contrib.admin and display them 
> in the requested language (French in my case).
>
> My concern is that "django-admin.py makemessages -a" command doesn't 
> understand just as well and it creates those translation messages again in 
> my auth app's locale files. But I don't need them, or at least commented as 
> #fuzzy. Is it the normal behavior of that command or am I doing wrong ?
>
> Below is the example with the message "Reset my password":
>
> In django.contrib.admin locale files:
>
> - 
> path/to/python2.7/sites-packages/django/contrib/admin/locale/en/LC_MESSAGES/django.py
>
> #: templates/registration/password_reset_form.html:21
> msgid "Reset my password"
> msgstr ""
>
>  
> - 
> path/to/python2.7/sites-packages/django/contrib/admin/locale/fr/LC_MESSAGES/django.py
>
> #: templates/registration/password_reset_form.html:21
> msgid "Reset my password"
> msgstr "Réinitialiser mon mot de passe"
>
>
> In my password_reset template of my auth app:
>
> - auth/templates/auth/password_reset.html:
>
> *{% load i18n %}*
>
> 
>
>
>
> In my auth app's locale files after typing "cd path/to/myproject; cd 
> auth; django-admin.py makemessages -a":
>
> - auth/locale/en/LC_MESSAGES/django.po:
>
> #: templates/auth/password_reset.html:36
> msgid "Reset my password"
> msgstr ""
>
>
> - auth/locale/en/LC_MESSAGES/django.po:
>
> #: templates/auth/password_reset.html:36
> msgid "Reset my password"
> msgstr ""
>
>
> Here my settings:
>
> - myproject/settings.py:
>
>
> MIDDLEWARE_CLASSES = (
> 'django.middleware.cache.UpdateCacheMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.locale.LocaleMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> 'django.middleware.cache.FetchFromCacheMiddleware',
> )
>
> LANGUAGE_CODE = 'en-us'
>
> LANGUAGES = (
> ('fr', _('French')),
> ('en', _('English')),
> )
>
> TIME_ZONE = 'UTC'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = True
>
>
> Here my config:
>
> - Mac OS X 10.9.2
> - python 2.7.6
> - gettext 0.18.3 (installed via homebrew)
>
> Thanks for your help.
>
> Cheers,
>
> Selenite Vingt-Neuf
>
>

-- 
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/7ce57726-5f35-43cb-9c2e-3eb22592c862%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
I am running into a challenge.  For both examples below everything is good 
except when I move the ugettext() to a separate file.
Good: After running the django-admin.py makemessages -l es, both examples 
produce the appropriate .po file.
Good: I change ../locale/es/LC_MESSAGES/django.po
  #: nav/views.py: 
  msgid "name" 
 msgstr "nombre"
Good: django-admin.py compilemessages
Good: I get the appropriate file, ../locale/es/LC_MESSAGES/django.mo 

This is a simplified version of what is happening.

---
Good: 1 - This works: when ugettext is within the view.
*file : /project/app/views.py*

...other imports
from django.utils.translation import ugettext

class BaseView(ContextMixin, View):
template = 'base.html'

def get(self, request, *args, **kwargs):
context = self.get_context_data()
return render(request, self.template, context)

def get_context_data(self, **kwargs):
   
   context['translate_this']= ugettext('name')
   return context
-

Bad: 2 - This Fails: when ugettext is in another file
*file : /project/app/views.py   *

...other imports
from .mytext import FROM_ANOTHER_FILE

class BaseView(ContextMixin, View):
template = 'base.html'

def get(self, request, *args, **kwargs):
context = self.get_context_data()
return render(request, self.template, context)

def get_context_data(self, **kwargs):
   
   context['translate_this']= FROM_ANOTHER_FILE
   return context

*file: /project/app/text.py   *
from django.utils.translation import ugettext

FROM_ANOTHER_FILE = ugettext('name')

-

The primary difference between the two examples is that when I separate 
ugettext() to another file - it fails.  
The result is that 'name' never converts to 'nombre' when changing the 
language.  
It works fine in example 1, 'name' and 'nombre' change depending on 
language selected but not in example 2.

-- 
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/2302f88c-2050-4265-bf22-6e4d34a2b486%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
Sorry for the large text... I forget to change it - I guess I am going 
blind :-)

On Friday, May 30, 2014 6:51:35 PM UTC-7, visionary800 wrote:
>
> I am running into a challenge.  For both examples below everything is good 
> except when I move the ugettext() to a separate file.
> Good: After running the django-admin.py makemessages -l es, both examples 
> produce the appropriate .po file.
> Good: I change ../locale/es/LC_MESSAGES/django.po
>   #: nav/views.py: 
>   msgid "name" 
>  msgstr "nombre"
> Good: django-admin.py compilemessages
> Good: I get the appropriate file, ../locale/es/LC_MESSAGES/django.mo 
>
> This is a simplified version of what is happening.
>
>
> ---
> Good: 1 - This works: when ugettext is within the view.
> *file : /project/app/views.py*
>
> ...other imports
> from django.utils.translation import ugettext
>
> class BaseView(ContextMixin, View):
> template = 'base.html'
>
> def get(self, request, *args, **kwargs):
> context = self.get_context_data()
> return render(request, self.template, context)
>
> def get_context_data(self, **kwargs):
>
>context['translate_this']= ugettext('name')
>return context
>
> -
>
> Bad: 2 - This Fails: when ugettext is in another file
> *file : /project/app/views.py   *
>
> ...other imports
> from .mytext import FROM_ANOTHER_FILE
>
> class BaseView(ContextMixin, View):
> template = 'base.html'
>
> def get(self, request, *args, **kwargs):
> context = self.get_context_data()
> return render(request, self.template, context)
>
> def get_context_data(self, **kwargs):
>
>context['translate_this']= FROM_ANOTHER_FILE
>return context
>
> *file: /project/app/text.py   *
> from django.utils.translation import ugettext
>
> FROM_ANOTHER_FILE = ugettext('name')
>
> -
>
> The primary difference between the two examples is that when I separate 
> ugettext() to another file - it fails.  
> The result is that 'name' never converts to 'nombre' when changing the 
> language.  
> It works fine in example 1, 'name' and 'nombre' change depending on 
> language selected but not in example 2.
>

-- 
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/ad352064-6e11-4f0c-89a6-a0fab2d091c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems to be a bug in makemessages management command

2014-05-30 Thread Russell Keith-Magee
Hi Андрей,

On Fri, May 30, 2014 at 9:50 PM, Андрей Меньков <
nothingelsematte...@gmail.com> wrote:

> May be it would better to post this to "Django developers" mailing list?
>

Possibly - if you think you've found a bug, django-developers is a better
audience for that. django-users is a better audience if you're just unsure
if you're using a command/API correctly.


> пятница, 30 мая 2014 г., 15:53:56 UTC+3 пользователь Андрей Меньков
> написал:
>
>> Django management command doesn't recognize multiline strings as strings
>> to localize. So such strings don't appear in resulting django.po files
>> after running command
>>
>> For example for such a string
>>
>> {code}
>> {{ _(''' fhsdafjkshdfjkasdhfksj
>>  ytyerwtuiwyertuiywert''') }}
>> {code}
>>
>> I'm a little unclear what's going on here. Are you using Django
templates, or Jinja2? Django's template language doesn't allow multi-line
template tags, and _() isn't valid translation syntax in a Django template.

If you're using Jinja2, then the source of the bug may be in whatever layer
you're using to integrate Jinja2 templates into Django.


> I might be the bug of GNU xgettext utility, because makemessages uses it
>> to produce *.po files, but after running xgettext I became sure that the
>> problem is in the makemessages command, not xgettext.
>>
>> I ran xgettext using the following command
>>
>> xgettext --keyword=gettext_noop --keyword=gettext_lazy
>> --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy
>> --keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2
>> --keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2
>> --keyword=npgettext_lazy:1c,2,3 --from-code UTF-8
>> --add-comments=Translators --from-code utf-8 -d django -p ./output_dir -L
>> Python temp_i18n_template.html
>>
>> After running this command I got file output_dir/django.po with specified
>> string inside it.
>>
>> What I can do now? What do you think about this "bug" ?
>>
>> P.S. It's my first attempt to contribute to Django somehow. So please do
>> not judge strictly). I haven't found anywhere about this problem and about
>> its' fixes too.
>>
>
The make messages is really just a thin wrapper around xgettext; the
command you issued manually seems to match pretty closely what Django's
makemessages command should be doing. If you're not getting the right
output from Django's management command, it possible you've found a bug. If
I had to guess, it will be with the code that is discovering the templates
that need to be processed, but it's impossible to say for sure without your
code in front of me.

If you want to do some digging, the relevant code is in
django/core/management/commands/makemessages.py. Most of the code in that
file is dedicated to building a command line and executing a call to
xgettext; it should be fairly straightforward to understand. If you *do*
find a problem, please open a ticket and let us know; or follow up with a
thread on the django-dev if you're uncertain if the problem is a bug in
Django or your own usage.

Yours,
Russ Magee %-)

-- 
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/CAJxq84-YDHe69Mx_u%2ByBKk%3DpBq%2B3iQffAUu0fO83VafYYMUBCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django ugettext translation glitch or as designed?

2014-05-30 Thread Ramiro Morales
On Fri, May 30, 2014 at 10:51 PM, visionary800  wrote:
> Bad: 2 - This Fails: when ugettext is in another file
> file : /project/app/views.py
>
> ...other imports
> from .mytext import FROM_ANOTHER_FILE
>
> class BaseView(ContextMixin, View):
> template = 'base.html'
>
> def get(self, request, *args, **kwargs):
> context = self.get_context_data()
> return render(request, self.template, context)
>
> def get_context_data(self, **kwargs):
>
>context['translate_this']= FROM_ANOTHER_FILE
>return context
>
> file: /project/app/text.py
> from django.utils.translation import ugettext
>
> FROM_ANOTHER_FILE = ugettext('name')
>
> -
>
> The primary difference between the two examples is that when I separate
> ugettext() to another file - it fails.
> The result is that 'name' never converts to 'nombre' when changing the
> language.
> It works fine in example 1, 'name' and 'nombre' change depending on language
> selected but not in example 2.

In example 2 your translatable literal is defined and marked-up with
the translation function at the global scope of the module. In these
cases you need to use lazy translations, i.e. ugettext_lazy() instead
of ugettext().

Read the the relevant documentation carefully for the details:

https://docs.djangoproject.com/en/1.6/topics/i18n/translation/#lazy-translation

HTH,

-- 
Ramiro Morales
@ramiromorales

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


Re: Django Template - problema

2014-05-30 Thread Erick Brockes
Kevin, Thank you.

If you don't mind, I'm kind of new in django.

I've got the following response in the browser:

{'tipo_conjuge': }

Could you help me out on how to proceed?


2014-05-30 18:45 GMT-03:00 Kelvin Wong :

> In relacaoconjugetipouniao_form.html
>
> Add this tag...then refresh...
>
> {{ form.fields }}
>
> Should give you more info about what fields are in the form and what
> widget they are using.
>
> ie. 'tipo_conjuge': django.forms.fields.TypedChoiceField object
>
> Also check your html source in a browser. Sometimes CSS mistakes hide
> things.
>
> K
>
>
> On Friday, May 30, 2014 7:40:01 AM UTC-7, ebrockes wrote:
>>
>> I have the following problem. The field "tipo_conjuge" is not showing as
>> I wanted. Could somebody tell me what is the problem?
>>
>> Best regards,
>> Erick
>>
>>
>> url. py
>>
>> ...
>> url(r'relacao/(?P\d+)/$', login_required(
>> CreateTipoRelacaoView.as_view()), name='cadastrarRelacaoTipo'),
>> ...
>>
>>
>> views.py
>>
>> ...
>> class CreateTipoRelacaoView(CreateView):
>> model = RelacaoConjugeTipoUniao
>> fields = ['tipo_conjuge','data_inicio','data_fim']
>>
>> def form_valid(self, form):
>> relacao = get_object_or_404(RelacaoConjuge,
>> id=self.kwargs['relacao'])
>> form.instance.relacao = relacao
>> return super(CreateTipoRelacaoView, self).form_valid(form)
>>
>>
>> models.py
>>
>> class RelacaoConjugeTipoUniao(models.Model):
>>
>> TIPO_CONJUGE = (
>> ('CA', _('Casados')),
>> ('UE', _('União estável')),
>> ('OU', _('Outros')),
>> )
>>
>> tipo_conjuge = models.CharField(_('Tipo'), max_length=2,
>> choices=TIPO_CONJUGE, blank=False, null=False)
>> data_inicio = models.DateField(_('Data de início'))
>> data_fim = models.DateField(_('Data de término'))
>>...
>>
>>
>> relacaoconjugetipouniao_form.html
>>
>> {% extends 'pessoa/base_voltar.html' %}
>> {% block content %}
>> {% csrf_token %}
>> {{ form.non_field_errors }}
>> 
>> {{ form.tipo_conjuge.errors }}
>> Tipo de União:
>> {{ form.tipo_conjuge }}
>> 
>> 
>> {{ form.data_inicio.errors }}
>> Data de início:
>> {{ form.data_inicio }}
>> 
>> 
>> {{ form.data_fim.errors }}
>> Data de término:
>> {{ form.data_fim }}
>> 
>> 
>> 
>> 
>> 
>> Voltar
>> {% endblock content %}
>>
>>  --
> 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/2c343d4f-48e4-4e5a-a02f-137edc1b0de2%40googlegroups.com
> 
> .
> 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/CALUDr%2B3nKPfXvLg5LoXzPScv9%2BbhaCxNuHBSZrU1dmiZ6AxJ-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django ugettext translation glitch or as designed?

2014-05-30 Thread visionary800
Thank you Ramiro!  That was it - I changed to ugettext_lazy() and it worked!

I want to separate the text from the templates - this is why I want to 
place the text in a separate file.  Placing the text within the template is 
a d

What approach should I take to just separate the text from from the 
templates and views?  I want the text easy to edit without worrying about 
tags around the text.  Any suggestions? 

-- 
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/2bad743d-d190-4ed1-affb-932e5c1e9236%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Template - problema

2014-05-30 Thread Erick Brockes
Problem solved by replacing on models.py:

TIPO_CONJUGE = (
('CA', _('Casados')),
('UE', _('União estável')),
('OU', _('Outros')),
)

by

TIPO_CONJUGE = (
('CA', _('Casados')),
('UE', _('Uniao estavel')),
('OU', _('Outros')),
)

I'll see how to solve this issue. Any clues?


2014-05-31 0:11 GMT-03:00 Erick Brockes :

> Kevin, Thank you.
>
> If you don't mind, I'm kind of new in django.
>
> I've got the following response in the browser:
>
> {'tipo_conjuge':  0xb4dcb7ec>}
>
> Could you help me out on how to proceed?
>
>
> 2014-05-30 18:45 GMT-03:00 Kelvin Wong :
>
> In relacaoconjugetipouniao_form.html
>>
>> Add this tag...then refresh...
>>
>> {{ form.fields }}
>>
>> Should give you more info about what fields are in the form and what
>> widget they are using.
>>
>> ie. 'tipo_conjuge': django.forms.fields.TypedChoiceField object
>>
>> Also check your html source in a browser. Sometimes CSS mistakes hide
>> things.
>>
>> K
>>
>>
>> On Friday, May 30, 2014 7:40:01 AM UTC-7, ebrockes wrote:
>>>
>>> I have the following problem. The field "tipo_conjuge" is not showing as
>>> I wanted. Could somebody tell me what is the problem?
>>>
>>> Best regards,
>>> Erick
>>>
>>>
>>> url. py
>>>
>>> ...
>>> url(r'relacao/(?P\d+)/$', login_required(
>>> CreateTipoRelacaoView.as_view()), name='cadastrarRelacaoTipo'),
>>> ...
>>>
>>>
>>> views.py
>>>
>>> ...
>>> class CreateTipoRelacaoView(CreateView):
>>> model = RelacaoConjugeTipoUniao
>>> fields = ['tipo_conjuge','data_inicio','data_fim']
>>>
>>> def form_valid(self, form):
>>> relacao = get_object_or_404(RelacaoConjuge,
>>> id=self.kwargs['relacao'])
>>> form.instance.relacao = relacao
>>> return super(CreateTipoRelacaoView, self).form_valid(form)
>>>
>>>
>>> models.py
>>>
>>> class RelacaoConjugeTipoUniao(models.Model):
>>>
>>> TIPO_CONJUGE = (
>>> ('CA', _('Casados')),
>>> ('UE', _('União estável')),
>>> ('OU', _('Outros')),
>>> )
>>>
>>> tipo_conjuge = models.CharField(_('Tipo'), max_length=2,
>>> choices=TIPO_CONJUGE, blank=False, null=False)
>>> data_inicio = models.DateField(_('Data de início'))
>>> data_fim = models.DateField(_('Data de término'))
>>>...
>>>
>>>
>>> relacaoconjugetipouniao_form.html
>>>
>>> {% extends 'pessoa/base_voltar.html' %}
>>> {% block content %}
>>> {% csrf_token %}
>>> {{ form.non_field_errors }}
>>> 
>>> {{ form.tipo_conjuge.errors }}
>>> Tipo de União:
>>> {{ form.tipo_conjuge }}
>>> 
>>> 
>>> {{ form.data_inicio.errors }}
>>> Data de início:
>>> {{ form.data_inicio }}
>>> 
>>> 
>>> {{ form.data_fim.errors }}
>>> Data de término:
>>> {{ form.data_fim }}
>>> 
>>> 
>>> 
>>> 
>>> 
>>> Voltar
>>> {% endblock content %}
>>>
>>>  --
>> 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/2c343d4f-48e4-4e5a-a02f-137edc1b0de2%40googlegroups.com
>> 
>> .
>> 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/CALUDr%2B3Y3icVm5u_bykh6_SJqDdHV77xsCLKxo1-yoec4EpN0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Enumerating objects in foreign key in the admin

2014-05-30 Thread Christophe Pettus
Right now, when one has a foreign key field in a detail page in the admin, it 
appears to enumerate the objects (one at a time) in order to build the pop-up.  
Obviously, if the other side of the foreign key relationship has a lot of 
entries, this can be a problem.  Short of doing a different, custom widget, is 
there a way to avoid this?
--
-- Christophe Pettus
   x...@thebuild.com

-- 
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/DBC6EF68-4DE3-432B-9237-D3973D80825F%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Enumerating objects in foreign key in the admin

2014-05-30 Thread Russell Keith-Magee
Hi Christophe,

The built-in way to handle this is to add a `raw_id_fields` declaration to
your ModelAdmin or Inline definition. This will replace the pulldown select
widget (populated with every possible value) with a single text input that
stores the primary key of the related object, plus a popup that makes it
easy (well… easier) to find the right PK.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields

Of course, a custom widget might give you a better UI, but if you're just
looking to make it work and not drag the rendering of the admin UI page to
a crawl, it works.

Yours,
Russ Magee %-)

On Sat, May 31, 2014 at 1:17 PM, Christophe Pettus  wrote:

> Right now, when one has a foreign key field in a detail page in the admin,
> it appears to enumerate the objects (one at a time) in order to build the
> pop-up.  Obviously, if the other side of the foreign key relationship has a
> lot of entries, this can be a problem.  Short of doing a different, custom
> widget, is there a way to avoid this?
> --
> -- Christophe Pettus
>x...@thebuild.com
>
> --
> 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/DBC6EF68-4DE3-432B-9237-D3973D80825F%40thebuild.com
> .
> 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/CAJxq84-ZxjTnJD%2B0jVGkYstK%3DeHV-nbj0gXYOmkCE_%2B7VnHgeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


saving backbonejs model with django backend

2014-05-30 Thread Eddilbert Macharia
Hi Guys,

how do i save a backbone model in the database ??

here is how i have tried it and the errors i am getting, please assist ,
/*
*
*
* the field model
*
*
*/
var fieldModel=Backbone.Model.extend({
defaults:{
name:'',
type:'',
placeholder:'',
},
urlRoot:'form',
initialize:function(){
this.on('invalid',function(model,error){
alert(error);
})
},
validate:function(attrs){
if(! $.trim(attrs.name) || ! $.trim(attrs.type)){
return 'Name can not be blank'
}
}

});


/*
*
*
* the collection of fields
*
*
*/
 
var fieldCollections=Backbone.Collection.extend({
model:fieldModel,
urlRoot:'form',
});


/*
*
*
* The collection of all elements view
*
*
*/
var allFieldsView=Backbone.View.extend({
el:'#designArea',
//template:,
initialize:function(){
this.render();
this.listenTo(this.collection,'add',this.displayOneField)
},
events:{
'click #saveDesignedForm':'saveDesignedForm',
},
render:function(){
this.collection.each(this.displayOneField,this);
return this;

},
// display each field
displayOneField:function(field){
// create a fields view based on each model that is in the 
collection
var oneFieldDisplay =new fieldView({model:field});
// append the each models fieldview 
// using fieldview created using the model get the el method

this.$el.find('#formDesign').append(oneFieldDisplay.render().el);
},


// save all the models in a collection
saveDesignedForm:function(){
this.collection.each(function(element){
element.save()
})
}

});

the url.py has the following path

  url(r'^form-save',saveFormDesign),

from the chrome console i get the following request payload on save

   1. {"name":"default name","type":"text","placeholder":"the placeholder 
   goes here"}


and this is my view

@csrf_exempt
def saveFormDesign(request):
ClientData.objects.create(name='demo',fields=request)
return HttpResponse(request)

here is my stack trace
ProgrammingError at /dataapp/form
can't adapt type 'WSGIRequest'

Request Method: POST
Request URL: http://localhost:8000/dataapp/form
Django Version: 1.6.3
Python Executable: C:\Python27\python.exe
Python Version: 2.7.6
Python Path: ['C:\\projects', 
'C:\\Python27\\lib\\site-packages\\setuptools-3.2-py2.7.egg', 
'C:\\Python27\\lib\\site-packages\\pip-1.5.4-py2.7.egg', 
'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 
'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 
'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 
'C:\\Python27\\lib\\site-packages']
Server time: Sat, 31 May 2014 08:19:45 +0300
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'south',
 'DataApp',
 'django_hstore',
 'tastypie')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in 
get_response
  114. response = wrapped_callback(request, 
*callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\csrf.py" in 
wrapped_view
  57. return view_func(*args, **kwargs)
File "C:\projects\DataApp\views.py" in saveFormDesign
  253. ClientData.objects.create(name='demo',fields=request)
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in create
  157. return self.get_queryset().create(**kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in create
  319. obj.save(force_insert=True, using=self.db)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  545.force_update=force_update, 
update_fields=update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save_base
  573. updated = self._save_table(raw, cls, force_insert, 
force_update, using, update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in _save_table
  654. result = self._do_insert(cls._base_manager, using, 
fields, update_pk, raw)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in _do_insert
  687.using=using, raw=raw)
File "C:\Python27\lib\site-packages\django\db\models\mana

Re: Suggestions for Paginating a Growing Django Queryset

2014-05-30 Thread Babatunde Akinyanmi
Like someone said, you can consider caching the entire queryset. That will
definitely impact memory. Another idea is to play with timestamps in your
query since you don't care if the results are not accurate. Maybe you
shouldn't paginate then you can draw out the whole queryset, render them on
the page and hide some with JavaScript. This could also impact memory at
the server end and loading time on the client.

Personally i don't see anything wrong with users seeing a blog on two pages
because they will know that the reason is because things have changed.
 On 30 May 2014 23:12, "Riegie Godwin"  wrote:

> Hello everyone!
>
>   I've been stuck for about a week trying to figure this out. Been on
> all sorts of blogs and asked questions on stackoverflow in hopes that it
> would lead in the right direction. I would like to know what you think I
> could do.
>
> Let's say I have 4 models, a User model, Blog Model, Hashtag and a Comment
> model. Users can create blogs, users can comment on them and blogs can be
> tagged by the blog owner from the comments or the blog description itself.
> If I we're to best describe this, think of Instagram. You can hashtag your
> photo when your uploading it, and afterwards by commenting on it.
>
> Here are the models:
>
> #models.py
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class Blog(models.Model):
>user = models.ForeignKey(User)
>description = models.CharField(max_length=140, blank=True)
>blog_text = models.CharField(max_length=5000,  blank=True)
>related_hashtags = models.ManyToManyField('Hashtag',
> related_name = 'tagged_post', null=True, blank=True)
>
>
> class Comment(models.Model):
>user = models.ForeignKey(User)
>comment = models.CharField(max_length=140, blank=True)
>
> class Hashtag(models.Model):
>user = models.ForeignKey(User)
>comment = models.CharField(max_length=140, blank=True)
>count = models.IntegerField(default=1)
>
> Pretty simple. A blog can have multiple hashtags and a hashtag can belong
> to multiple blogs. When a user creates a blog, I check the description
> string for any hashtags using the following function below:
>
>  hash_tags = re.findall(r'#(\w+)', blog.description, re.UNICODE)[:30] #
> each blog can have a maximum of 30 hashtags
>  if hash_tags:
> for hash_tag in hash_tags:
>try:
>   oldHashtag =
> Hashtag.objects.get(hashtag = hash_tag)
>   oldHashtag.count =
> oldHashtag.count + 1
>   oldHashtag.save()
>
> blog.related_hashtag.add(oldHashtag)
>
>except Hashtag.DoesNotExist:
>newHashtag =
> Hashtag.objects.create(hashtag = lowercase_hash_tag)
>
>  blog.related_hashtag.add(newHashtag)
>
> I hope so far everything makes sense. I do the same as above whenever a
> Comment object is created.
>
> Now let's imagine the hashtag #acdc is really popular, about 20-40 blogs
> are added to that hashtag about every millisecond.
>
> If the user searches for #acdc, I would like to show the latest 20 blogs
> that have just been added with #acdc, and as the user loads more, I'll show
> the next 20. They are ordered in DESC order of insertion.
>
> I had to resort to RAW SQL since Django couldn't order the queryset by the
> pk of the ManyToManyField, many others suggested using a through table, but
> for legacy reasons, I did it this way:
>
> SELECT * FROM django_blog INNER JOIN django_blog_related_hashtag ON (
> django_blog.id = django_blog_related_hashtag.blog_id ) INNER JOIN
> django_hashtag ON ( django_blog_related_hashtag.hashtag_id =
> django_hashtag.id ) WHERE ( django_hashtag.hashtag = 'acdc' ) ORDER BY
> django_blog_related_hashtag.id DESC LIMIT 20
>
> If the user wanted to view page two, I'd simply add an OFFSET at the end
> of the query. A simple function like so:
>
> OFFSET = (page_number -1) * 20
>
> This all works great, but for web apps like Instagram or Twitter or this
> Blog app I just made, if the queryset is constantly growing, the user is
> not always in sync with the most recent data. Which is perfectly fine, I
> don't care about that. But what I do care about is that the next page that
> they request must contain the results that are suppose to come after the
> ones they have just received. If I don't account for this, users might see
> blogs that they have already seen from previous pages because of the
> growing queryset. Someone mentioned caching the entire queryset, but
> wouldn't that have a large memory over head?
>
> I'm looking forward to hearing your thoughts and suggestions.
>
> Kind Regards,
>
> Riegie Godwin
>
> --
> You received this message because you are subscribed to the Google Groups