Re: How to add fields to an existing model dynamically? Also how to modify existing field of a model dynamically?

2015-07-30 Thread SriPrad
Hi,
Thanks for the quick response.
I understand that it is not typical to have dynamic model.
However the requirements I have need to allow the admin to make changes/ create 
models dynamically.
I have looked at South library. However my understanding is that it is not 
supported for Django 1.7 and later versions. It seems that the functionality is 
merged in Django 1.7.

Please advise.

Regards,
Srinivasa Pradeep



On Thursday, July 30, 2015 at 5:08:07 PM UTC+5:30, vicherot wrote:
> IMHO (maybe i'm wrong) i think that its not quite good modify your database 
> structure dynamically to often, maybe you must to think a better design of 
> your model.
> I'm working on a Health bussiness in Argentina and never need to 
> change the database structure to modify a medical form. (for now)
> 
> 
> Now, for your exclusive problem, maybe using south (just like the project you 
> say) you can do the changes to your database dinamically.
> 
> Regards!
> 
> 
> 
> 
> 
> --
> Rafael E. Ferrero
> 
> 
> 
> 2015-07-30 5:01 GMT-03:00 SriPrad :
> 
> Hi,
> I am new to Django and Python!. 
> I am using Django 1.8.3 along with Python 3.2 and using sqlite as the 
> database.
> I am trying to setup a site using Django wherein the model is created 
> dynamically( For eg: a Medical form)
> The fields of the form are stored in db and the model created dynamically 
> (reference: https://github.com/willhardy/dynamic-models)
> The admin guys can modify the fields of this medical form from the admin 
> site. At this time, I would like to modify the model to match the schema 
> modifications done by admin guys.
> I understand prior  to Django 1.7, there was django.db.models.loading module 
> that helped in this.
> 
> With the current version of Django, how can I add/modify/delete the fields of 
> the dynamic model dynamically?
> 
> Your help and suggestions are most welcome.
> 
> Regards,
> Srinivasa Pradeep
> 
> 
> 
> 
> 
> -- 
> 
> 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/6a62db2f-5dd7-417c-9d6b-fbbed6b5a149%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/4d02e9dc-98dc-4120-ad19-caac524bc57c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to deploy django 1.8 on openshift

2015-07-30 Thread Gpzim Pacheco
This tuto is great.

https://github.com/Gpzim98/Django-OpenShift-1.8

>
>

-- 
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/8b9fd708-21d0-4272-8bef-ee0c05170ab1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Restricting CreateView

2015-07-30 Thread James Schneider
get_queryset() is designed to filter down a list of of available objects
that a generic view can use. The reason that CreateView doesn't have one is
because the purpose of CreateView is to create a new object to operate on
(meaning that there shouldn't be anything in the database that can be
queried).

You shouldn't use get_queryset() to control access to the view itself, only
use it to filter down the available objects already within the database.
Those two ideas sound similar, but are handled differently.

What you are likely looking for is a row level (per object) permission
system (the built-in permission system is table level). There are several
packages available to assist:

https://www.djangopackages.com/grids/g/authorization/

Many of the authentication packages also have authorization (permission
checking) built in.

https://www.djangopackages.com/grids/g/authentication/

django-guardian is probably the most popular of all of these. I haven't
used any of them personally.

The authorization package you choose should work in tandem with the
get_queryset() methods you've probably already defined.

-James


On Thu, Jul 30, 2015 at 3:20 AM, David  wrote:

> Hi
>
> Using other CBV's I can use get_queryset to filter out users that don't
> belong to a certain group. AFAIK createview doesn't have get_queryset.
>
> Can I achieve this with CreateView somehow?
>
> The context is:
>
> All forums: have to be a member of X to view anything
> A particular Forum: have to be a member of Y to view at all
> CreateView need to be a member of Y to view/submit
>
> Thank you
>
> --
> 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/49fb6fc3-7b86-424c-af97-d50824762dd2%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/CA%2Be%2BciVVh5tPmPxcWUEJay82%3DBxPQvLtv1DbiHEKUdLw6bjHGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Introduction to Pulpo-Forms

2015-07-30 Thread Luciano Ferrari


Last April we finished the development of a dynamic form builder, called 
pulpo-forms, to use within a Django Project. Today we’re excited to 
announce that we’re making the source code available on GitHub 
.

Here is a short list with the most important features of this new open 
source tool:

   - Enable users to create forms with an easy drag&drop UI
   - Angular directives to render the form  
   and the dashboard
   - Multi pages forms.
   - RESTful API
   - Customizable fields validations such as required, length,etc.
   - Conditional enable for fields based on other field values (e.g. in a 
   food preferences survey, hide the *‘How do you like your steak?’ *question 
   to someone that previously answered that’s a vegetarian).
   - Conditional enable for form pages based on other field values.
   - Versions and drafts.
   - Integration for Django models.
   - Signals.
   - Configurable actions – show a thank you screen, send an email, etc.
   - Built-in statistics in the dashboard
   - Basic field types answers can be filtered in the dashboard

Since it was made to be flexible from the beginning, this can be extended 
to add new fields, validations and so on.

We hope you enjoy it, and of coursed we are open to comments, questions and 
pull 
requests !

-- 
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/55f128d8-8aa2-4a79-9adc-37e2463e3cab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Does imports of related models affect cascade deletion?

2015-07-30 Thread Markus Amalthea Magnuson
I will fetch the actual piece of code and build a small test case out of
it, will reply again in this thread when I have some more info.

On Thu, Jul 30, 2015 at 6:39 PM, Marc Aymerich  wrote:

> On Thu, Jul 30, 2015 at 3:38 PM, Markus Amalthea Magnuson
>  wrote:
> > Hey,
> >
> > I stumbled upon a piece of code and a comment that says this:
> >
> > Deleting a model object that has related objects will only cascade delete
> > those objects if their models have been imported.
> >
> > Is this true? I have not found it in the documentation and would like to
> add
> > a reference to the code comment so others won't be as confused as I am.
>
> Is this models module called models.py and does it live inside a
> Django application listed in INSTALLED_APPS?
>
>
> --
> Marc
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/wLiEuzqUVeQ/unsubscribe.
> To unsubscribe from this group and all its topics, 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%2BDCN_tKE56qJPJ339uL0Zo%2BvEDSsPdTnLMODHC_3H4hd856dw%40mail.gmail.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/CAOXH8SXRVShSrLuPjZuPDPhbEEdc-Bi9v5JQm-xHf181iCzMKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re. My Django Book.

2015-07-30 Thread Steve Burrus
* Say I was wondering if anyone else has ever read this particulkar Django 
book called "Sams Teach Yourself Django in 24 Hours" I checked out of the 
library yesterday? [yeah I know it's one of the "24 hours" series] Does it 
really teach the beginner a lot of things concerning Django?*


   

-- 
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/de78f7fa-cb87-4d88-a9c6-886f43841bb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Custom Field

2015-07-30 Thread Aurélio Moreira
I wanted your help to make a custom Field Type'm studying it at the time 
and I'm not getting. I'll put it to you here the code I've done so far. I 
hope your help.

http://pastebin.com/81Lq86Xn Field
http://pastebin.com/CvATavnd Widget
http://pastebin.com/2tNcKtgfForm

-- 
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/10405523-935b-447d-9dea-70e4c6d68de4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Hi Tom,

That was approximately what I was planning to do, I shall do some 
experimenting to see if I can do any more.  I was just wondering if there 
was a clever feature for this sort of thing, as ORMs seem pretty magic 
already!

Thanks,
Rich

On Thursday, 30 July 2015 17:15:40 UTC+1, Tom Evans wrote:
>
> On Thu, Jul 30, 2015 at 4:08 PM, Rich Lewis  > wrote: 
> > Dear All, 
> > 
> > I'm new to the Django ORM, and quite new to ORMs in general.  I have two 
> > models (lets call them A and B) between which I have an interesting 
> mapping. 
> > There are precisely 2 B instances associated with each A instance.  Each 
> A 
> > instance can have many B instances.  The order of Bs are important for 
> As. 
> > 
> > I want to do something like this: 
> > 
> > class A(models.Model): 
> >   b_1 = models.ForeignKey(B) 
> >   b_2 = models.ForeignKey(B) 
>
> This would fail here, when you have more than one foreign key to the 
> same model, you must supply a related_name argument on one of them, 
> which is used for the inverse relation on the related object. Which 
> leads us in to... 
>
> > 
> > class B(models.Model): 
> >   pass 
> > 
> > Such that i can do: 
> > 
>  b1, b2, b3 = B(), B(), B() 
>  a1, a2 = A(b_1=b1, b_2=b2), A(b_1=b2, b_2=b3) 
>  b2.as 
> > [, ] #(order doesn't matter) 
>
> Typically, B instances would have an attribute named 'a_set' (the 
> lower case model name of the model it is related to, with "_set" 
> appended). When you have multiple relationships with the same model, 
> as I mentioned you must supply your own related_name arguments. In 
> which case, with the models you mentioned, you could then do something 
> like this: 
>
> >>> b2.a1_set.all() | b2.a2_set.all() 
> > [, ] 
>
> > 
> > I expect I could eventually do something a bit hacky that would work, 
> but 
> > what would be the best way to handle this? 
>
> I would say the above is the hacky way. You could have the same B 
> assigned to b_1 and b_2 and would have duplicates in the set, and no 
> way to specify DB constraints to limit it. 
>
> Given that you anticipate being able to retrieve all the A's for a 
> particular B, regardless of how they are related, I would model it as 
> a M2M with a through table holding any additional information about 
> the relationship, using the through table to add DB level constraints. 
>
> Cheers 
>
> Tom 
>

-- 
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/daa601f5-12d5-44fe-8c58-f2f052629261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Oops sorry I meant every B instance can have multiple A instances.  Sorry!

On Thursday, 30 July 2015 16:21:37 UTC+1, monoBOT monoBOT wrote:
>
>
> 2015-07-30 16:08 GMT+01:00 Rich Lewis >:
>
>> There are precisely 2 B instances associated with each A instance.  Each 
>> A instance can have many B instances
>
>
> Isnt that a contradiction?
>
>
>
> -- 
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>  

-- 
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/40eadb77-0205-403d-92a8-52859645c4fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Does imports of related models affect cascade deletion?

2015-07-30 Thread Marc Aymerich
On Thu, Jul 30, 2015 at 3:38 PM, Markus Amalthea Magnuson
 wrote:
> Hey,
>
> I stumbled upon a piece of code and a comment that says this:
>
> Deleting a model object that has related objects will only cascade delete
> those objects if their models have been imported.
>
> Is this true? I have not found it in the documentation and would like to add
> a reference to the code comment so others won't be as confused as I am.

Is this models module called models.py and does it live inside a
Django application listed in INSTALLED_APPS?


-- 
Marc

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


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread 'Tom Evans' via Django users
On Thu, Jul 30, 2015 at 4:08 PM, Rich Lewis  wrote:
> Dear All,
>
> I'm new to the Django ORM, and quite new to ORMs in general.  I have two
> models (lets call them A and B) between which I have an interesting mapping.
> There are precisely 2 B instances associated with each A instance.  Each A
> instance can have many B instances.  The order of Bs are important for As.
>
> I want to do something like this:
>
> class A(models.Model):
>   b_1 = models.ForeignKey(B)
>   b_2 = models.ForeignKey(B)

This would fail here, when you have more than one foreign key to the
same model, you must supply a related_name argument on one of them,
which is used for the inverse relation on the related object. Which
leads us in to...

>
> class B(models.Model):
>   pass
>
> Such that i can do:
>
 b1, b2, b3 = B(), B(), B()
 a1, a2 = A(b_1=b1, b_2=b2), A(b_1=b2, b_2=b3)
 b2.as
> [, ] #(order doesn't matter)

Typically, B instances would have an attribute named 'a_set' (the
lower case model name of the model it is related to, with "_set"
appended). When you have multiple relationships with the same model,
as I mentioned you must supply your own related_name arguments. In
which case, with the models you mentioned, you could then do something
like this:

>>> b2.a1_set.all() | b2.a2_set.all()
> [, ]

>
> I expect I could eventually do something a bit hacky that would work, but
> what would be the best way to handle this?

I would say the above is the hacky way. You could have the same B
assigned to b_1 and b_2 and would have duplicates in the set, and no
way to specify DB constraints to limit it.

Given that you anticipate being able to retrieve all the A's for a
particular B, regardless of how they are related, I would model it as
a M2M with a through table holding any additional information about
the relationship, using the through table to add DB level constraints.

Cheers

Tom

-- 
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/CAFHbX1%2B7-KieRLGT_hG-UDC6zeyg%2Bb8d%3D7XtEK4EEM8nFvzFng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-30 Thread Michael Herrmann
I'm very relieved - thanks Tim! If I can help, please let me know.

Best,
Michael

On 30 July 2015 at 17:56, Tim Graham  wrote:

> We are working on that solution:
> https://github.com/django/django/pull/5060
>
>
> On Thursday, July 30, 2015 at 7:19:31 AM UTC-4, mic...@herrmann.io wrote:
>>
>> Hi all,
>>
>> I've just been bitten by this new "feature" as well. I completely don't
>> understand this design decision of 1.8. It is very useful to be able to
>> create model classes without having to save them to the database, not just
>> for unit tests but also for experimenting in the shell. The new "feature"
>> breaks this which is a huge PITA, in my opinion.
>>
>> Could the check for RelatedObjectDoesNotExist not be performed in the
>> save(...) method by Django? Then we would get the best of both worlds: You
>> can create models however you like in unit tests or the shell, and at the
>> same time if you erroneously attempt to save a foreign key which doesn't
>> yet exist you would get the exception.
>>
>> I feel strongly about this because it is very much against the ease of
>> use which I like so much about Django. Is this the appropriate forum to
>> request this as a feature for 1.9 (or another future Django version)?
>>
>> Thanks,
>> Michael
>>
>> On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>>>
>>> Hi Roland,
>>>
>>> On 07/16/2015 07:46 AM, Roland Swingler wrote:
>>> >> i'll just say that Django tests don't favor too much into the "unit"
>>> > test spectrum;
>>> >
>>> > That is what I'm seeing - it is the same with rails out of the box as
>>> > well. I guess I'm just curious to know whether:
>>> >
>>> > a) the 'unit' test end of the spectrum is feasible if that's what you
>>> like
>>> > b) what is available in the Django community (if anything, whether
>>> > libraries, 'ways-of-doing-things' etc.) to support this if it is an
>>> > approach one wants to take.
>>>
>>> I also write model tests using unsaved models where possible. I don't
>>> think it has significant test isolation benefits (your tests are still
>>> integrating with most of the ORM), but it does have test-suite speed
>>> benefits!
>>>
>>> I understand why the change was made in 1.8 to disallow assigning an
>>> unsaved object to a ForeignKey/OneToOneField attribute; in production
>>> code that would almost always be a bug. Personally, though, I've never
>>> been bitten by that bug, I'm confident I could easily find and fix such
>>> a bug if I did write it, and I don't want to give up the ability to use
>>> related unsaved models in tests. So I just use my own subclasses of
>>> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment =
>>> True` set on them (essentially reverting the safety change in 1.8). I
>>> haven't attempted to switch it on dynamically for testing; that should
>>> be possible using a setting and a custom subclass, but I wouldn't choose
>>> to do that; differences between test and production behavior should be
>>> minimized.
>>>
>>> Carl
>>>
>>>


-- 
[image: Inline image 1]

Michael Herrmann, MSc
Alser Straße 18/26
1090 Wien
Tel.: +43 699 11 65 16 40
Email: mich...@herrmann.io

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


Re: Testing related models without saving

2015-07-30 Thread Tim Graham
We are working on that solution: https://github.com/django/django/pull/5060

On Thursday, July 30, 2015 at 7:19:31 AM UTC-4, mic...@herrmann.io wrote:
>
> Hi all,
>
> I've just been bitten by this new "feature" as well. I completely don't 
> understand this design decision of 1.8. It is very useful to be able to 
> create model classes without having to save them to the database, not just 
> for unit tests but also for experimenting in the shell. The new "feature" 
> breaks this which is a huge PITA, in my opinion.
>
> Could the check for RelatedObjectDoesNotExist not be performed in the 
> save(...) method by Django? Then we would get the best of both worlds: You 
> can create models however you like in unit tests or the shell, and at the 
> same time if you erroneously attempt to save a foreign key which doesn't 
> yet exist you would get the exception.
>
> I feel strongly about this because it is very much against the ease of use 
> which I like so much about Django. Is this the appropriate forum to request 
> this as a feature for 1.9 (or another future Django version)?
>
> Thanks,
> Michael
>
> On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>>
>> Hi Roland, 
>>
>> On 07/16/2015 07:46 AM, Roland Swingler wrote: 
>> >> i'll just say that Django tests don't favor too much into the "unit" 
>> > test spectrum; 
>> > 
>> > That is what I'm seeing - it is the same with rails out of the box as 
>> > well. I guess I'm just curious to know whether: 
>> > 
>> > a) the 'unit' test end of the spectrum is feasible if that's what you 
>> like 
>> > b) what is available in the Django community (if anything, whether 
>> > libraries, 'ways-of-doing-things' etc.) to support this if it is an 
>> > approach one wants to take. 
>>
>> I also write model tests using unsaved models where possible. I don't 
>> think it has significant test isolation benefits (your tests are still 
>> integrating with most of the ORM), but it does have test-suite speed 
>> benefits! 
>>
>> I understand why the change was made in 1.8 to disallow assigning an 
>> unsaved object to a ForeignKey/OneToOneField attribute; in production 
>> code that would almost always be a bug. Personally, though, I've never 
>> been bitten by that bug, I'm confident I could easily find and fix such 
>> a bug if I did write it, and I don't want to give up the ability to use 
>> related unsaved models in tests. So I just use my own subclasses of 
>> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment = 
>> True` set on them (essentially reverting the safety change in 1.8). I 
>> haven't attempted to switch it on dynamically for testing; that should 
>> be possible using a setting and a custom subclass, but I wouldn't choose 
>> to do that; differences between test and production behavior should be 
>> minimized. 
>>
>> Carl 
>>
>>

-- 
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/24147436-a0fa-49c8-bd80-e4e74d052319%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Does imports of related models affect cascade deletion?

2015-07-30 Thread Tim Graham
No, import of related models shouldn't affect cascade deletion. Please open 
a bug report with steps to reproduce if that's actually the case. Possibly 
it could be a bug that's fixed by the app loading refactor in 1.7.

On Thursday, July 30, 2015 at 9:38:09 AM UTC-4, Markus Amalthea Magnuson 
wrote:
>
> Hey,
>
> I stumbled upon a piece of code and a comment that says this:
>
> Deleting a model object that has related objects will only cascade delete 
> those objects if their models have been imported.
>
> Is this true? I have not found it in the documentation and would like to 
> add a reference to the code comment so others won't be as confused as I am.
>
> Here's an illustration (from memory, disregard if code is not valid 
> python):
>
> mymodel.py:
>
> from django.db import models
>
> class MyModel(models.Model):
> foo = models.CharField()
> bar = models.CharField()
>
>
> my_other_model.py:
>
> from django.db import models
> from mymodel import MyModel
>
> class MyOtherModel(models.Model):
> baz = models.CharField()
> bar = models.ForeignKey(MyModel)
>
>
> some_source_file.py:
>
> from mymodel import MyModel
>
> # Without this line, deleting MyModel objects will not delete its related
> # MyOtherModel objects (?):
> from my_other_model import MyOtherModel
>
> obj = MyModel.objects.get(pk=123)
> obj.delete()
>

-- 
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/b41ea21c-aafb-4268-8549-9337b0cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save data from form FileField to DB Django

2015-07-30 Thread Javier Guerra Giraldez
On Thu, Jul 30, 2015 at 10:40 AM, user07285  wrote:
> I have a model and have added a Form FileField to take a file and save all
> their contents for a particular object. The FileField doesn't need to be in
> the database hence not added as a model.fileField. The content from the file
> should be read , parsed and added to the synonym_type.


first of all, it's almost always a _terrible_ idea to save files in
database fields.  Yes, it works, no, it's not "faster"; it creates a
heavy overhead on an already sensitive part of your system.

but, if you want to do it, the easiest way is to use a Storage Object
that manages the saving and thus you can keep the FieldFile
abstraction (either from a FileField or a File() object).  Even
better, when you get to migrate to a different (better!) storage, you
only have to modify the settings and the code can stay the same.

check DjangoStorages [1], it includes a "Database" backend [2] (and
other like S3, libcloud, etc)

[1] https://django-storages.readthedocs.org/en/latest/index.html
[2] https://django-storages.readthedocs.org/en/latest/backends/database.html

-- 
Javier

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


How to save data from form FileField to DB Django

2015-07-30 Thread user07285
I have a model and have added a Form FileField to take a file and save all 
their contents for a particular object. The FileField doesn't need to be in 
the database hence not added as a model.fileField. The content from the 
file should be read , parsed and added to the synonym_type. 

**model.py** 

molecule = models.ForeignKey('MoleculeDictionary', blank=False, 
null=False)
synonym_type = models.ForeignKey('SynonymType')
   
synonym_name = models.CharField(max_length=50, blank=True)
def __unicode__(self):
return u'%s' % (self.synonym_name)


And this is how I add Form field to the models(admin)page. 

**form.py**
 

from django.forms import ModelForm
from django.forms import *
import pdb
import os
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.files import File
from idg.models.molecule_synonym import MoleculeSynonym


class MoleculeSynonymForm(ModelForm):
file_upload = FileField(required=False)
print "YES" 
def save(self, commit=True):
print 'saving...'
file_upload = self.cleaned_data.get('file_upload', None)
file_upload.seek(0)
with open("../../Downloads/model_file_upload.txt", 'r') as 
f:
model_file = File(f)
names = model_file.read()
print(names)

form = MoleculeSynonymForm(names)

return super(MoleculeSynonymForm, 
self).save(commit=commit)
#

class Meta:
model = MoleculeSynonym


I have two questions: 

1. How should I save the names to the Synonym_name for a chosen 
synonym_type and molecule. I use sqlite. My current code doesn't throw any 
errors other than: 

> The molecule synonym "" was added successfully.

2. How do I get the "full path for the file" without hardcoding them in the 
open statement. 




-- 
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/338d22f3-8314-427d-9bf4-7f1412b89700%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread monoBOT
2015-07-30 16:08 GMT+01:00 Rich Lewis :

> There are precisely 2 B instances associated with each A instance.  Each A
> instance can have many B instances


Isnt that a contradiction?



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

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


Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Dear All,

I'm new to the Django ORM, and quite new to ORMs in general.  I have two 
models (lets call them A and B) between which I have an interesting 
mapping.  There are precisely 2 B instances associated with each A 
instance.  Each A instance can have many B instances.  The order of Bs are 
important for As.

I want to do something like this:

class A(models.Model):
  b_1 = models.ForeignKey(B)
  b_2 = models.ForeignKey(B)

class B(models.Model):
  pass

Such that i can do:

>>> b1, b2, b3 = B(), B(), B()
>>> a1, a2 = A(b_1=b1, b_2=b2), A(b_1=b2, b_2=b3)
>>> b2.as
[, ] #(order doesn't matter)

I expect I could eventually do something a bit hacky that would work, but 
what would be the best way to handle this?

Thanks in advance,

Richard

-- 
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/3250c3c4-7598-4104-8a7b-1a0aa313a253%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Does imports of related models affect cascade deletion?

2015-07-30 Thread Markus Amalthea Magnuson
Hey,

I stumbled upon a piece of code and a comment that says this:

Deleting a model object that has related objects will only cascade delete 
those objects if their models have been imported.

Is this true? I have not found it in the documentation and would like to 
add a reference to the code comment so others won't be as confused as I am.

Here's an illustration (from memory, disregard if code is not valid python):

mymodel.py:

from django.db import models

class MyModel(models.Model):
foo = models.CharField()
bar = models.CharField()


my_other_model.py:

from django.db import models
from mymodel import MyModel

class MyOtherModel(models.Model):
baz = models.CharField()
bar = models.ForeignKey(MyModel)


some_source_file.py:

from mymodel import MyModel

# Without this line, deleting MyModel objects will not delete its related
# MyOtherModel objects (?):
from my_other_model import MyOtherModel

obj = MyModel.objects.get(pk=123)
obj.delete()

-- 
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/4991f097-ae07-4075-89c5-908df7b4ccf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add fields to an existing model dynamically? Also how to modify existing field of a model dynamically?

2015-07-30 Thread Rafael E. Ferrero
IMHO (maybe i'm wrong) i think that its not quite good modify your database
structure dynamically to often, maybe you must to think a better design of
your model.
I'm working on a Health bussiness in Argentina and never need to change the
database structure to modify a medical form. (for now)


Now, for your exclusive problem, maybe using south (just like the project
you say) you can do the changes to your database dinamically.

Regards!

--
Rafael E. Ferrero

2015-07-30 5:01 GMT-03:00 SriPrad :

> Hi,
> I am new to Django and Python!.
> I am using Django 1.8.3 along with Python 3.2 and using sqlite as the
> database.
> I am trying to setup a site using Django wherein the model is created
> dynamically( For eg: a Medical form)
> The fields of the form are stored in db and the model created dynamically
> (reference: https://github.com/willhardy/dynamic-models)
> The admin guys can modify the fields of this medical form from the admin
> site. At this time, I would like to modify the model to match the schema
> modifications done by admin guys.
> I understand prior  to Django 1.7, there was django.db.models.loading
> module that helped in this.
>
> With the current version of Django, how can I add/modify/delete the fields
> of the dynamic model *dynamically*?
>
> Your help and suggestions are most welcome.
>
> Regards,
> Srinivasa Pradeep
>
> --
> 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/6a62db2f-5dd7-417c-9d6b-fbbed6b5a149%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/CAJJc_8VQ6WgvmN5sr%3DFLpge%2B7MujOGqk9TC5%3DSQhRerkkv%2Bgaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing related models without saving

2015-07-30 Thread michael
Hi all,

I've just been bitten by this new "feature" as well. I completely don't 
understand this design decision of 1.8. It is very useful to be able to 
create model classes without having to save them to the database, not just 
for unit tests but also for experimenting in the shell. The new "feature" 
breaks this which is a huge PITA, in my opinion.

Could the check for RelatedObjectDoesNotExist not be performed in the 
save(...) method by Django? Then we would get the best of both worlds: You 
can create models however you like in unit tests or the shell, and at the 
same time if you erroneously attempt to save a foreign key which doesn't 
yet exist you would get the exception.

I feel strongly about this because it is very much against the ease of use 
which I like so much about Django. Is this the appropriate forum to request 
this as a feature for 1.9 (or another future Django version)?

Thanks,
Michael

On Thursday, 16 July 2015 18:37:39 UTC+2, Carl Meyer wrote:
>
> Hi Roland, 
>
> On 07/16/2015 07:46 AM, Roland Swingler wrote: 
> >> i'll just say that Django tests don't favor too much into the "unit" 
> > test spectrum; 
> > 
> > That is what I'm seeing - it is the same with rails out of the box as 
> > well. I guess I'm just curious to know whether: 
> > 
> > a) the 'unit' test end of the spectrum is feasible if that's what you 
> like 
> > b) what is available in the Django community (if anything, whether 
> > libraries, 'ways-of-doing-things' etc.) to support this if it is an 
> > approach one wants to take. 
>
> I also write model tests using unsaved models where possible. I don't 
> think it has significant test isolation benefits (your tests are still 
> integrating with most of the ORM), but it does have test-suite speed 
> benefits! 
>
> I understand why the change was made in 1.8 to disallow assigning an 
> unsaved object to a ForeignKey/OneToOneField attribute; in production 
> code that would almost always be a bug. Personally, though, I've never 
> been bitten by that bug, I'm confident I could easily find and fix such 
> a bug if I did write it, and I don't want to give up the ability to use 
> related unsaved models in tests. So I just use my own subclasses of 
> ForeignKey and OneToOneField with `allow_unsaved_instance_assignment = 
> True` set on them (essentially reverting the safety change in 1.8). I 
> haven't attempted to switch it on dynamically for testing; that should 
> be possible using a setting and a custom subclass, but I wouldn't choose 
> to do that; differences between test and production behavior should be 
> minimized. 
>
> Carl 
>
>

-- 
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/acbdd6a3-077e-43d2-bb42-72ecf235bcb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to add fields to an existing model dynamically? Also how to modify existing field of a model dynamically?

2015-07-30 Thread SriPrad
Hi,
I am new to Django and Python!. 
I am using Django 1.8.3 along with Python 3.2 and using sqlite as the 
database.
I am trying to setup a site using Django wherein the model is created 
dynamically( For eg: a Medical form)
The fields of the form are stored in db and the model created dynamically 
(reference: https://github.com/willhardy/dynamic-models)
The admin guys can modify the fields of this medical form from the admin 
site. At this time, I would like to modify the model to match the schema 
modifications done by admin guys.
I understand prior  to Django 1.7, there was django.db.models.loading 
module that helped in this.

With the current version of Django, how can I add/modify/delete the fields 
of the dynamic model *dynamically*?

Your help and suggestions are most welcome.

Regards,
Srinivasa Pradeep

-- 
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/6a62db2f-5dd7-417c-9d6b-fbbed6b5a149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Restricting CreateView

2015-07-30 Thread David
Hi

Using other CBV's I can use get_queryset to filter out users that don't 
belong to a certain group. AFAIK createview doesn't have get_queryset.

Can I achieve this with CreateView somehow?

The context is:

All forums: have to be a member of X to view anything
A particular Forum: have to be a member of Y to view at all
CreateView need to be a member of Y to view/submit

Thank you

-- 
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/49fb6fc3-7b86-424c-af97-d50824762dd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Models.clean() how to raise ValidationError WITH error_code and show field_based errors in the Form-Template?

2015-07-30 Thread ThomasTheDjangoFan
Hi guys,

I got a working model.clean() method that actually does a great job showing 
the errors in the assigned html-form. *The view actually marks single 
invalid fields red, which I find really important*.

*BUT:*
Now I want to *write a test* for that model and would love to *test for 
error_codes*.

*Does anyone know how to raise an error_code-exception within the model and 
keep the view rendering the invalid-fields correctly?*

Ok... I think it's easier to understand with some code:


class MyNotebookModel(models.Model):
note = models.TextField()
name = models.CharField()

def clean(self):
errors = defaultdict(list)
# errors = {}  # does NOT work with view

# Validate self.note
if 'P.S. I love django!' not in self.note:
message = 'BadAss: Give some credits to Django!'
errors['note'].append(message)
# errors.append(ValidationError(_(message), code=1))  # does 
NOT work in view

# Validate self.name
if 'Steven' not in self.note:
message = 'BadAss: I only allow names with Steven'
errors['note'].append(message)
# errors.append(ValidationError(_(message), code=2))  # does 
NOT work in view

if len(errors):
raise ValidationError(errors)


class TestMyNotebookCreateView(CreateView):
# in my View I want to show errors by field and mark the error-fields 
RED
# it works with the above approach, but NOT with error_codes



class TestMyNotebookModelTest(unittest):
def test_clean(self):
# I'd love to be able to do a test like this one
# and valide the error code!

# Lets get an error-message
with self.assertRaises(ValidationError) as test:
model = MyNotebookModel()
model.note = 'Now this is a valid one. P.S. I love django!'
model.name = 'Britney is gonna fail - Hit me Baby One More 
Time!'
model.clean()
model.save()
# validate that the error messages has the right code
the_exception = test.exception
self.assertEqual(the_exception.error_code, 2)


Any ideas how to make this work?
What is best practise?

-- 
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/a5d1a379-5896-4743-ada9-8494f6d57284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Learning Django problems

2015-07-30 Thread Stas soroka
The code for this application is in my GitHub repository, link to witch i 
provided at the end of my original post. Look carefully ;)

среда, 29 июля 2015 г., 14:21:01 UTC+3 пользователь roshan.pannase написал:
>
> sir i am a new learner  can you send me the code of this application
>
> On Wed, Jul 29, 2015 at 11:33 AM, Stas soroka  > wrote:
>
>> I'm currently reading a book "Learning Django Web Development". Even 
>> thoug I followed the book carefully, it says, that my page should look like 
>> this:
>>
>>
>> 
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> When, in fact, my page looks like that:
>>
>> 
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> I will be very greatful, if someone tell me, what can cause such a 
>> problem.
>>
>> If it's needed - a link to my GitHub repository, with a code, that I 
>> currently have - GitHub 
>>
>> -- 
>> 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/d7f386bb-16ba-473e-81ea-bab24013d251%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/fff6def8-45a3-4eed-a154-8ac09658ff2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Learning Django problems

2015-07-30 Thread Stas soroka
As it turned out - the problem was in misconfigured STATICFILES_DIRS  variable. 
When i fixied it - everything became as it should be

среда, 29 июля 2015 г., 14:53:04 UTC+3 пользователь Robin Lery написал:
>
> Do u have static directory? And does it have the required resources?
> On 29 Jul 2015 16:50, "Roshan Pannase" > 
> wrote:
>
>> sir i am a new learner  can you send me the code of this application
>>
>> On Wed, Jul 29, 2015 at 11:33 AM, Stas soroka > > wrote:
>>
>>> I'm currently reading a book "Learning Django Web Development". Even 
>>> thoug I followed the book carefully, it says, that my page should look like 
>>> this:
>>>
>>>
>>> 
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> When, in fact, my page looks like that:
>>>
>>> 
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> I will be very greatful, if someone tell me, what can cause such a 
>>> problem.
>>>
>>> If it's needed - a link to my GitHub repository, with a code, that I 
>>> currently have - GitHub 
>>>
>>> -- 
>>> 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/d7f386bb-16ba-473e-81ea-bab24013d251%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...@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/CAGkvgN%3DgcihZhqy-zm%3D7BrAMOY%3D4VmbnQi1o%2B_L3jNQDACTB-w%40mail.gmail.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/ed85c13f-1a5a-4216-b002-6efc89fa8160%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Want to change template based on full_name(request.user.username)

2015-07-30 Thread sarfaraz ahmed
Thanks, this worked like awesome..!!!




On Thu, Jul 30, 2015 at 3:06 AM, Alex Heyden  wrote:

> {{user}} is implicitly sent in the request, so it might be worth trying to
> sort out what specifically went wrong when you say
> {{user.is_authenticated}} went wrong.
>
> Here's a fully functioning example of some things you can do with the user
> object:
>
> {% block header %}
>  role="navigation">
> 
> Home
> 
> {% if user.is_authenticated %}
> 
> 
> Projects
> Reports
> {% if user.is_staff %}
> Usage
> {% endif %}
> 
> 
> {% if user.is_superuser %}
> Settings
> {% endif %}
> 
>  data-toggle="dropdown">
> {% if user.first_name %}
> Welcome, {{ user.first_name }}
> {% else %}
> Welcome, {{ user.username }}
> {% endif %}
> 
> 
> Sign Out
> 
> 
> 
> 
> {% endif %}
> 
> {% endblock %}
>
> On Wed, Jul 29, 2015 at 4:20 PM, sarfaraz ahmed 
> wrote:
>
>> Hello All,
>>
>> I am facing an issue in my first django project. I am newbie. So, please
>> help me in detail. I don't want to use {{full_name}} in all the views. I
>> saw few post which says {{user.is_authenticated}} can be used. I tried but
>> it was not working. Passing {'full_name':request.user.username} to each is
>> very hectic. Also, not sure to this in one of my view where i am using
>> password_change. View is mentioned below where i am not able pass full_name.
>>
>> This is mentioned below is my *navigation.html*
>>
>>
>> 
>>   
>> 
>> 
>>   > data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
>> aria-expanded="false">
>> Toggle navigation
>> 
>> 
>> 
>>   
>>   
>> 
>>
>> 
>> > id="bs-example-navbar-collapse-1">
>>   
>> Home > class="sr-only">(current)
>> Sale > class="sr-only">(current)
>> About Us
>>
>>   
>> 
>>   
>>
>> {%if full_name %}
>>
>> 
>>
>>   > role="button" aria-haspopup="true" aria-expanded="false">{{full_name}}> class="caret">
>>   
>> My Account
>> Orders
>> Profile
>> Change
>> Password
>> 
>> Logout
>>   
>> 
>> {% else %}
>> Register
>> Login
>> {% endif %}
>>   
>> 
>>   
>> 
>>
>>
>> 
>> @login_required
>> def
>> my_change_password_view(request,template_name='useraccount/password_change_form.html'):
>> return password_change(request,template_name)
>>
>> --
>>
>> Please help.
>>
>> Regards,
>> Sarfaraz Ahmed
>>
>> --
>> 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/f8521d79-c2a0-40a9-bd4e-0a90625264fe%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/CA%2Bv0ZYW0S-UpbAvFY4RuVUQXKKRPsK3DhX1qefSQYvgFk3c3aw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Thanks with regards,
Sarfaraz Ahmed

-- 
You received