Rendering Form Fields That Are Passed To Context Inside Of An Object

2016-04-08 Thread David McWilliams
tl:dr -- How do I explicitly render the fields in a form that's passed to 
the context dictionary within an object?

I'm building a page right now that shows a list of documents to the user. 
 Each document has a type, a status, a list of images associated with it, 
and finally a document update form with a few fields in it.  Because all of 
these pieces of data belong together, I created a class to group them for 
display (this is a simplified version for example only):

class Document:
def __init__(self, doc_type, doc_status):
self.doc_type = doc_type
self.doc_status = doc_status
self.update_form = DocUpdateForm()

def doc_view(request):
# ... some other stuff to get the raw data ...

documents = []

for raw_doc in raw_document_data:
documents.append(Document(raw_doc.doc_type, raw_doc.doc_status))

context['documents'] = documents

return render_to_response('doc_list.html', context)

This all worked fine, because then in my template I was able to do 
something nice and simple like this:

...
Documents

  Document TypeDocument StatusUpdate
  {% for doc in documents %}

  {{ doc.doc_type }}
  {{ doc.doc_status }}
  {{ doc.update_form }}

  {% endfor %}


Piece of cake, right?

Well, now we want to change the page so that some of the form fields are 
inside of one div, and some inside of another one so that they can be next 
to one another instead of oriented vertically.  I consulted the Django 
documentation here: 
https://docs.djangoproject.com/en/1.9/topics/forms/#rendering-fields-manually 
and 
decided to render each of the fields myself.  This resulted in something 
like:

...
Documents

  Document TypeDocument StatusUpdate
  {% for doc in documents %}

  {{ doc.doc_type }}
  {{ doc.doc_status }}
  {{ doc.update_form.field_1 }}
{{ doc.update_form.field_2 }}


  {% endfor %}



Unfortunately, all this does is render the text "doc.update_form.field_1" 
instead of the form field.  It's the same behavior that I see when I 
accidentally try to reference a key that doesn't exist in the context 
dictionary.

I can, of course, just write the form fields HTML by hand . . . but 
goshdarnit, I'm a developer, and I want to know why the lazy way isn't 
working.  Do I need to reference the form fields differently than the 
documentation suggests?  Is it because I'm passing the forms to the context 
inside of another object?  Should I be learning how to use formsets and/or 
fieldsets?

This app uses Django 1.8, in case that's important.

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


Re: Multidimensional form requirements

2016-04-08 Thread Babatunde Akinyanmi
I don't know if I'm off target but.

I'm presently work on something like this where I have have to save three
models at a go. One model is a stand alone while the other two have a
foreign key to the stand alone model which is a many to one relationship.
So to implement the many to one where I can save many of the dependent
models together with the standalone models, I made use of inline formset
and no problems thus far.
On Apr 8, 2016 5:16 PM, "Scot Hacker"  wrote:

> I need to build a pretty complex / non-standard form and am looking for
> advice on the overall architecture. Consider the following models:
>
> class UserProfile(User):
>   ... standard set of fields
>
>
> class ProfileExtra():
>   ForeignKey(UserProfile)
>   extratype (e.g. skill, work experience, website, publication, etc.)
>   ... another set of fields
>
>
> The idea is that, when editing a profile, a user can add an unlimited
> number of these ProfileExtras to their profile. So a user might end up with:
>
> Profile
>   name
>   title
>   about
>   photo
> Skills
>   skill 1
>   skill 2
> Publications
>   pub1
>   pub2
>   pub3
> Jobs
>   job1
>   job2
>
>
> etc. When editing their profiles, they'll be able to add/edit/delete any
> of these *in place* without leaving the page (it'll be ajax.)
>
> So we have one core model and "n" number of related models. Obviously, a
> standard ModelForm can't encompass all of this cleanly. There are several
> things about this that just don't mesh well with Django's forms library. It
> deals with multiple model types, it deals with unknown additional numbers
> of a related model, it needs to be all ajax.
>
> I'm really not sure about the best way to put it all together. I'm
> thinking we probably won't use Django forms at all - just do standard JS to
> create/destroy html form inputs on the page dynamically. Consider the whole
> thing as one big form element, and it all gets submitted every time. In the
> receiving view, pull apart the POST request and process it all manually.
> Advantage: total control. Disadvantage: we lose all the magic provided by
> model and modelform validation.
>
> Another thought is that we could make e.g. "skills" into a single field
> and use ArrayField (we're on postgres) to store all of the related skills.
> Need to experiment with that.
>
> Have any of you solved a similar problem? Are good ways to meet the
> requirements while still being able to take advantage of Django form
> validation goodness? I'm all ears. Thanks.
>
> ./s
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a14486b-c7fc-4a99-a0b0-03774c04ae1e%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXN2uJ5yrPuGahV%3D0_yVYHgHspswoZyUaEhv6k6oTy_-ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: inventory in Django

2016-04-08 Thread Daniel Wilcox
>
> Sorry if this question seems basic, but I'm having trouble figuring out
> the best way to approach this on a high level.
>
> I'm at the beginning stages of building an ecommerce site,. Inventory
> changes regularly, and photos and descriptions need to be easy to update
> for my client. Is this an ajax problem or can this be done in views?  What
> are some elegant ways to approach this? I know this is a very common
> problem, which is great - direction would be helpful.
>
> Thank you.
>
> Becka
>
>
Hello, I don't know if there is an elegant way to approach this exactly...
but here are some thoughts.  I typically move from more pages to fewer as I
get messaging and more javascript working.  I recommend a similar approach
so you have something working the whole time (tests help) and can get a
feel for what is missing; maybe even bounce it off the client to see what
they think.

The other thing is that is you know what you're client is using it for --
just imagine using the product for the required processes and what is
needed at each step (read page) and draw the page on a piece of paper.
That'll help fill in your requirements.  Like, theoretically, "does the
loading dock staff need to update quantities?"  OK what would that look
like; 1) login, 2) create shipment 'object', 3) update product A through F
while shipment X is selected.  Stuff like that.


First get your models worked out -- figure out all the fields you'll need
for a product (this may be a client question).  You can put photos 'in' (I
use this term loosely, it stores a file path) the product listing model
itself to help associate the two.  Versatileimage does a great job -- and
down the road you can make the site fully responsive quite easily as it
supports resizing on the fly (and caches the result).

You have to think of how the data needs be stored to support the kind of
queries you want.  Like for inventory can a quantity of a product be a
discrete number?  It depends on the kind of product you're building -- for
a store, probably unless it is huge, but for a warehouse, probably not.  In
this case the decision is creating a 'Shipment' object or something of that
sort with relations to products or just having an IntegerField on a product
called 'quantity'.

Create some M->1 relations, or many to many if you need many categories per
product, between products and categories, production and shipments or some
other organizing principle.  You can always start with model views and then
theme them up.

Creating a store that can be updated is about the same.  You'll basically
do similar things to the admin console; for a product you'll have a form
input per field and use the most natural one you can -- the admin console
does a great job at this so you can look there for guidance on specific
form field types (date pickers, file upload, multi-select inputs, etc).

Ajax is kinda an old way to refer to the strategy but yes you can add that
at any point.  It might be helpful to define the pages that you want first
and you can always make views that return XML, or JSON, later.  Unless of
course you have a big ball of javascript already starting out in which case
serializers are your friend but not always.

In any case once you start serializing I find it helps define some ToDict()
methods on your models, or a top level abstract model for your app.  The
method should do what it sounds like -- clean up the object for
serialization (replace foreign keys with 'id' attributes, cast things to
string as necessary, the serializer will complain you'll know).


A little ramble-y but hope that helps, cheers,

=D

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


Re: How to know which models have changed and need make migrations?

2016-04-08 Thread C. Kirby
Are you sure you are adding your new migrations to your source control? It 
sounds like the model changes  are being correctly commited but the 
generated migrations are not.

On Friday, April 8, 2016 at 11:17:16 AM UTC-5, Neto wrote:
>
> I know, but in production is showing the message that I have to do 
> makemigrations.
> I need a command to know what models need to makemigrations
>
> Em quinta-feira, 7 de abril de 2016 14:50:54 UTC-3, Daniel Roseman 
> escreveu:
>>
>> You shouldn't ever need to make migrations in production. You make them 
>> in dev, commit to source control, deploy along with the rest of the code, 
>> then run the migrations in prod.
>>
>> -- 
>> DR.
>>
>

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


Re: Django 1.9 Woes

2016-04-08 Thread SillyInventor
I don't think so... The line I am getting hung up on is:
class Project(models.Model):
..
def approved_projects():
return Project.objects.filter(approved=True)

It seems that no matter how many things I remove from my URLs, if there is 
any reference to any model on the first build, it'll fail to migrate.

On Friday, April 8, 2016 at 7:26:04 AM UTC-4, Tim Graham wrote:
>
> Difficult for me to say for sure without having a sample project to debug. 
> Do you know if you have any module level queries in your project? Those are 
> generally to be avoided and may cause problems like this. See 
> https://groups.google.com/d/topic/django-developers/7JwWatLfP44/discussion 
> for some discussion.
>
> On Thursday, April 7, 2016 at 8:17:23 PM UTC-4, SillyInventor wrote:
>>
>> I am trying to transition to Django 1.9 from my 1.8 app. Simply creating 
>> the migrations for old databases is fine, but when I try to create a fresh 
>> database with migrate I get:
>>
>> "Error creating new content types. Please make sure contenttypes " 
>> RuntimeError: Error creating new content types. Please make sure 
>> contenttypes is migrated before trying to migrate apps individually. 
>>
>> I have tested this a fair bit, and I can get it to build fresh if I: 
>> remove my site from URLs, migrate, add it back, and migrate again... but 
>> that's super janky, and not the clean build I am looking for. It seems to 
>> be caused because in Django/core/management/base.py line 398 -> 
>> self.check() is called before the migration occurs, and the lack of a 
>> database throws an error and quits before setting up the database (catch 
>> 22). I have tested this by commenting this out, and that will also allow it 
>> to build the database.
>>
>> Anyone have any recommendations for what a good way to fix this is or 
>> what the underlying problem might be in my app?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/13be1e7c-ce44-468a-824f-883ba88caea6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to know which models have changed and need make migrations?

2016-04-08 Thread Neto
I know, but in production is showing the message that I have to do 
makemigrations.
I need a command to know what models need to makemigrations

Em quinta-feira, 7 de abril de 2016 14:50:54 UTC-3, Daniel Roseman escreveu:
>
> You shouldn't ever need to make migrations in production. You make them in 
> dev, commit to source control, deploy along with the rest of the code, then 
> run the migrations in prod.
>
> -- 
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/547338e9-71c7-455f-9acb-75d622077246%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multidimensional form requirements

2016-04-08 Thread Scot Hacker
I need to build a pretty complex / non-standard form and am looking for 
advice on the overall architecture. Consider the following models:

class UserProfile(User):
  ... standard set of fields


class ProfileExtra():
  ForeignKey(UserProfile)
  extratype (e.g. skill, work experience, website, publication, etc.)
  ... another set of fields


The idea is that, when editing a profile, a user can add an unlimited 
number of these ProfileExtras to their profile. So a user might end up with:

Profile
  name
  title
  about
  photo
Skills
  skill 1
  skill 2
Publications
  pub1
  pub2
  pub3
Jobs
  job1
  job2


etc. When editing their profiles, they'll be able to add/edit/delete any of 
these *in place* without leaving the page (it'll be ajax.)

So we have one core model and "n" number of related models. Obviously, a 
standard ModelForm can't encompass all of this cleanly. There are several 
things about this that just don't mesh well with Django's forms library. It 
deals with multiple model types, it deals with unknown additional numbers 
of a related model, it needs to be all ajax.

I'm really not sure about the best way to put it all together. I'm thinking 
we probably won't use Django forms at all - just do standard JS to 
create/destroy html form inputs on the page dynamically. Consider the whole 
thing as one big form element, and it all gets submitted every time. In the 
receiving view, pull apart the POST request and process it all manually. 
Advantage: total control. Disadvantage: we lose all the magic provided by 
model and modelform validation.

Another thought is that we could make e.g. "skills" into a single field and 
use ArrayField (we're on postgres) to store all of the related skills. Need 
to experiment with that.

Have any of you solved a similar problem? Are good ways to meet the 
requirements while still being able to take advantage of Django form 
validation goodness? I'm all ears. Thanks.

./s

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


What Python/Django code checkers do you recommend?...

2016-04-08 Thread Fred Stluka

  
  
Python/Django programmers,

What code review tools do you use?  Do you run them automatically
when checking in new code?  Do you recommend them?

Details:

I'm working on a large Python/Django Web app (1,000 files, 200,000
lines of code, 3.5 years) and spend a good chunk of my time
reviewing
code written by other team members.  I'd like to automate many of
the 
checks that I currently do manually:

- Coding standards violations
  -- Lack of logging
  -- Missing docstrings
  -- Hardcoded literals instead of named constants or utility
functions
  -- Standard columns in all DB tables (create_user, create_date, 
       update_user, update_date, status, etc.)
  -- etc.

- Architecture violations
  -- Doing things in the UI layer vs the business logic layer
  -- Respect the MVC boundaries
  -- etc.

- Logic errors

- Defensive coding
  -- Unchecked assumptions
  -- Missing else clauses on if statements
  -- Missing exception handlers
  -- Exception handlers that suppress errors
  -- etc.

- Security and data validation
  -- Vulnerability to injection attacks (SQL, JS, etc.)
  -- Data validation and security enforcement in browser vs. server
  -- etc.

- Massive inefficiencies
  -- Cursor loop vs more specific DB SELECT
  -- Caching opportunities
  -- etc.

- Reuse opportunities

- Lack of test cases

- DB migration issues
  -- Non-idempotent migrations
  -- Edited migrations
  -- Migrations that call non-migration code that might change

- User experience
  -- Show clear error messages in all cases of user error

- etc.

What tools do you recommend to automate such checks?  I'm currently
most interested in Python/Django, as well as _javascript_/CSS/HTML.

Some automation tools I've found include:
- Gerrit
  https://www.gerritcodereview.com/
- BitBucket Server (was Stash)
  https://www.atlassian.com/software/bitbucket/server/

Such automation tools support a workflow of human interactions for
manual code reviews (comments, replies, todos, etc.).  They also
call
code review tools like the following to scan the code automatically:
- Sonar (multiple languages via plugins)
   http://www.sonarqube.org/
- JSHint (_javascript_)
   http://jshint.com/
- JSLint (_javascript_)
   http://www.jslint.com/
- TSLint (TypeScript)
   https://palantir.github.io/tslint/
- PMD (mostly Java/JS, some Python)
   https://pmd.github.io/
- Checkstyle (Java, not Python)
   http://checkstyle.sourceforge.net/
- FindBugs (Java, not Python)
   http://findbugs.sourceforge.net/
- CodeNarc (Groovy and Java, not Python)
   http://codenarc.sourceforge.net/

I've also done a quick Google for Python/Django-specific tools:
- http://google.com/search?q=python+code+checkers
- http://google.com/search?q=django+code+checkers

and found:
- code-checker
   https://pypi.python.org/pypi/code-checker/
- PyChecker
   https://pypi.python.org/pypi/PyChecker
- Pyflakes
   https://pypi.python.org/pypi/pyflakes
- PyLint
   https://pypi.python.org/pypi/pylint
- pep8
   https://pypi.python.org/pypi/pep8
- Flake8 (wraps Pyflakes, pep8 and others)
   https://pypi.python.org/pypi/flake8
- Django Lint
   https://chris-lamb.co.uk/projects/django-lint
- QuantifiedCode
   https://www.quantifiedcode.com/

My IDE is PyCharm, which has the ability to check some things, but
I haven't yet investigated or configured it much.

What do you recommend?  Any good or bad experiences to share?

Thanks!
--Fred
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  

  




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


Re: I might need a different control panel... or do I?

2016-04-08 Thread Alex Heyden
The ability to update a profile can be as simple as a form for the model
object that holds the profile. The company's employees would have access to
Django admin. I've never used it personally, but django-user-accounts looks
like a way to avoid making a registration form if that's important to you.

On Fri, Apr 8, 2016 at 9:54 AM, Andrew Chiw 
wrote:

> I'm making a Django site for a company, and the way I envision it working
> is this:
> The company's employees can manage and validate clients who sign up on the
> site as well as link them to other services.
> Once the clients login, they have their own little control panel where
> they can change their own profile.
> The question is, can I or should I use Django's built in admin control
> panel for the clients' mini control panel?
> If not, then is http://django-user-accounts.readthedocs.org/en/latest/
> what I'm looking for?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9c3dfeb8-4c03-4622-9036-d70fd8a349eb%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Bv0ZYWTq_ZM3ipkEHVx-bJOQ0nirwZhuzHwMSf9zqi31H4cYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


inventory in Django

2016-04-08 Thread Becka R.
Hi,

Sorry if this question seems basic, but I'm having trouble figuring out the 
best way to approach this on a high level. 

I'm at the beginning stages of building an ecommerce site,. Inventory 
changes regularly, and photos and descriptions need to be easy to update 
for my client. Is this an ajax problem or can this be done in views?  What 
are some elegant ways to approach this? I know this is a very common 
problem, which is great - direction would be helpful. 

Thank you.

Becka

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


I might need a different control panel... or do I?

2016-04-08 Thread Andrew Chiw
I'm making a Django site for a company, and the way I envision it working 
is this:
The company's employees can manage and validate clients who sign up on the 
site as well as link them to other services.
Once the clients login, they have their own little control panel where they 
can change their own profile.
The question is, can I or should I use Django's built in admin control 
panel for the clients' mini control panel?
If not, then is http://django-user-accounts.readthedocs.org/en/latest/ what 
I'm looking for?

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


Should I use Django's builtin control panel for user facing purposes?

2016-04-08 Thread Andrew Chiw
I'm making a Django website for a company, where the company's employees 
will validate clients that sign up.
I'm thinking that the clients should have a mini control panel where they 
can change their own information only, while the company's employees have 
their own control panel where they can manage the clients and set whether 
or not they can change their information anymore, etc.
Should I / Can I use the built in Django control panel for this purpose?
If not, is django-user-accounts what I'm looking for?

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


Re: Dedicated pages for specific group members

2016-04-08 Thread Luis Zárate
Admin site is a great example of how to do that.  But in general you can
use in the view

if not request.user.has_perm("app name.perm name):
 Raise error like 404 or redirect to login

I think decorator is provide by django.

El jueves, 7 de abril de 2016, Larry Martell 
escribió:
> On Thu, Apr 7, 2016 at 3:56 AM, Luca Brandi  wrote:
>> Hi
>> is there a possibility to create some group members and let them have
some
>> secific url pages accessible to?
>> I am thinking to a kind of "if staff is member of group"open link
page..
>
> A quick google for this came up with:
>
>
http://stackoverflow.com/questions/4597401/django-user-permissions-to-certain-views
>
http://stackoverflow.com/questions/14335832/restrict-so-users-only-view-a-certain-part-of-website-django
>
http://stackoverflow.com/questions/12597864/how-to-restrict-access-to-pages-based-on-user-type-in-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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CACwCsY5TeX8Tm-sCFzD89-aaQ6XK18V%2BSwS2W-2HbMCKjNyFLw%40mail.gmail.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

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


Django get user details while registration for admin approval

2016-04-08 Thread Sudhanshu Shekhar
I am creating a Django app for which I want to be able to approve users 
before letting them login to the site. Am using django-user-accounts from 
pinax for the same. This approval step requires users to submit additional 
information such as their qualifications etc. This information should be 
asked after the registration page and stored with their profile. Even after 
they have confirmed their email, they shouldn't be able to login unless 
admin has approved them.

I am confused between two options :

1) Over-ride registration flow and show the profile edit form (where the 
profile has been created by post_save signal). But the profile-edit view 
should have some kind of authentication too right? how do I ensure it takes 
only the value passed from registration page and nothing else?

2) Login user after registration and show him his profile edit page. This 
page is the shown until he's filled it in after which he sees the waiting 
for admin approval text. This will be achieved with a mixin which will then 
be inherited by all my views. My concern here is the database fetch which 
will occur each time this mixin is run.

This seems like a pretty common flow. What's the best way to achieve this? 
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/298fa580-1cc9-4164-95fe-3f743094ca7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9 Woes

2016-04-08 Thread Tim Graham
Difficult for me to say for sure without having a sample project to debug. 
Do you know if you have any module level queries in your project? Those are 
generally to be avoided and may cause problems like this. See 
https://groups.google.com/d/topic/django-developers/7JwWatLfP44/discussion 
for some discussion.

On Thursday, April 7, 2016 at 8:17:23 PM UTC-4, SillyInventor wrote:
>
> I am trying to transition to Django 1.9 from my 1.8 app. Simply creating 
> the migrations for old databases is fine, but when I try to create a fresh 
> database with migrate I get:
>
> "Error creating new content types. Please make sure contenttypes " 
> RuntimeError: Error creating new content types. Please make sure 
> contenttypes is migrated before trying to migrate apps individually. 
>
> I have tested this a fair bit, and I can get it to build fresh if I: 
> remove my site from URLs, migrate, add it back, and migrate again... but 
> that's super janky, and not the clean build I am looking for. It seems to 
> be caused because in Django/core/management/base.py line 398 -> 
> self.check() is called before the migration occurs, and the lack of a 
> database throws an error and quits before setting up the database (catch 
> 22). I have tested this by commenting this out, and that will also allow it 
> to build the database.
>
> Anyone have any recommendations for what a good way to fix this is or what 
> the underlying problem might be in my app?
>

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


Re: Relation fields do not support nested lookups'

2016-04-08 Thread Jonty Needham
Sent too soon!

def calculate_score(self):
 return
x.m2m_set.filter(condition).aggregate(avg=Avg('m2m_subfield__score'))['avg']

returns the "Relation fields do not support nested lookups" error

On Fri, Apr 8, 2016 at 11:27 AM, Jonty Needham 
wrote:

> I'm not sure what this error means or how to resolve it. I'm guessing it's
> because in my model I'm trying to assign a field to the value of the
> average of all the many2many's from another field. But I can do this at the
> command line happily, yet when I put it on a submethod I can't do it, so I
> don't understand what's going wrong.
>
> This works:
>
> x.field_name =
> x.m2m_set.filter(condition).aggregate(avg=Avg('m2m_subfield__score'))['avg']
> x.save()
>
> Yes including the method on the model for x as follows:
>
> def calculate_score(self):
>
>

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


Relation fields do not support nested lookups'

2016-04-08 Thread Jonty Needham
I'm not sure what this error means or how to resolve it. I'm guessing it's
because in my model I'm trying to assign a field to the value of the
average of all the many2many's from another field. But I can do this at the
command line happily, yet when I put it on a submethod I can't do it, so I
don't understand what's going wrong.

This works:

x.field_name =
x.m2m_set.filter(condition).aggregate(avg=Avg('m2m_subfield__score'))['avg']
x.save()

Yes including the method on the model for x as follows:

def calculate_score(self):

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANOQRbyNgC4%3DTSMHnobqbW_LdPKP%3DoWStnSuNViwR3x%2BQyHF%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to use memcache with the queryset of the popup window of a raw field?

2016-04-08 Thread Victor
Under Django 1.9.5 and admin I'm developping an application "myapp" of which 
below you can see a simplified complete version.
 
Focusing on the  OrderOption ModelAdmin its inline  OrderDetailinline has a 
raw_id_field  related to the model Item. Now, when I click on the magnifying 
lens close to the raw_id_field a popup window - as expected- is fired which 
allows the user to choose an item from the Item model list.

Now, in the real application  the  popup window is somewhat of a bottleneck 
because it  requires about 4-6 sec. to be loaded owing to the fact that there 
are many records in the Item model. 
Luckily the Item model records change very slowly over time. In a week, say, no 
more than five  items are either added or modified or seldom deleted.
What I'd like to do is using the memcache backend  to save the queryset of the 
Item model - which will appear in the popup window - on my memcached server and 
recall this same queryset each time the popup window of the raw_id_field is 
fired avoiding the execution of the query.

My problem is that I don't know how to do it. Please help!

By the way, using the debug_toolbar I see that the popup window uses the view 
function django.contrib.admin.options.changelist_view, no arguments, and the 
corresponding  url name is myapp_item_changelist.
The sql query is obviously
SELECT "Items"."code", "Items"."Description", "Items"."Category" FROM "Items" 
ORDER BY"Items"."code" DESC

Thanks
Vittorio


==

models.py
from django.db import models

# Create your models here.
class Item(models.Model):
   code = models.CharField(primary_key=True,max_length=15,db_column='code')
   description = models.CharField(max_length=255, db_column='Description', 
db_index=True)
   category = models.IntegerField(choices=[(1,"Cat_1"),(2,"Cat_2")], 
db_column='Category',default=1)
   def __unicode__(self):
   return self.description
   class Meta:
   db_table = u'Items'

class Patient(models.Model):
   name = models.CharField(max_length=255, db_column='Description', 
db_index=True)
   def __unicode__(self):
   return self.name
   class Meta:
   db_table = u'Patients'

class Order(models.Model):
   patient = models.ForeignKey(Patient, db_column='patient')
   def __unicode__(self):
   return u"Ord.%s per %s" % (self.id_order, self.patient)
   class Meta:
   db_table = u'Order'

class OrderDetail(models.Model):
  id_order = models.ForeignKey(Order,db_column='id_order')
  item_code = models.ForeignKey(Item,verbose_name='Items')
  quantity = models.IntegerField(db_column='quantity',blank=True,default=0)
  class Meta:
   db_table = u'OrderDetail'
==

My admin.py
from django.contrib import admin
from myapp.models import *
# Register your models here.

class PatientOption(admin.ModelAdmin):
   list_display = ( 'name',)
   fields=( 'name',)

class ItemOption(admin.ModelAdmin):
   list_display = ( 'code','description')
   fields=('code','description')

class OrderDetailInline(admin.TabularInline):
   model=OrderDetail
   raw_id_fields = ['item_code',]
   fields=('item_code', 'quantity',)

class OrderOption(admin.ModelAdmin):
   readonly_fields = ['patient']
   list_display = ( 'patient',)
   fields=( 'patient',)
   inlines=[OrderDetailInline,]

admin.site.register(Patient,PatientOption)
admin.site.register(Item,ItemOption)
admin.site.register(Order,OrderOption)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/270EE134-AFDA-4E43-B59F-8CE8341EF323%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with dumpdata/loaddata

2016-04-08 Thread Ramiro Morales
It shouldn't. Are you sure you haven't opened and saved the json file with
a text editor that might be adding the BOM, e.g. Notepad before running
loaddata?
On Apr 7, 2016 9:17 PM,  wrote:

> Opening the JSON file in Notepad++ certainly gives some insight... It says
> it's encoded in USC-2 LE BOM. Converting it to UTF-8 with BOM in Notepad++
> solves the problem.
>
> Question though, why does dumpdata create files with an encoding that can
> not be used out of the box with loaddata?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b3f4fbbf-bcad-4376-8ed1-aa476b8c8a88%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF-BeSfPadGMGShP-0K4NCyfiqNFktSOXkYdGz7fQSMnTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.