Getting instance of current in django site admin

2012-09-21 Thread Krish
I have following code in my admin.py

class PackageForm(forms.ModelForm):
activity = forms.CharField(required=False)

class Meta:
model = Package

class PackageAdmin(AjaxSelectAdmin):
form = PackageForm

admin.site.register(Package, PackageAdmin)

So while editing package, I want to change certain value of Package object. 
how can I do this?

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



Re: My "Contributors" page Conundrum

2012-09-21 Thread JJ Zolper
Thanks Thomas.

Now does anyone have any legitimate help? Because I'm stuck.

Thanks,

JJ

On Thursday, September 20, 2012 8:53:59 PM UTC-4, Thomas wrote:
>
>  On 9/20/12 5:28 PM, JJ Zolper wrote:
>  
> Anyone have any ideas?
>
> Yes, Melvyn did.
>
> hth
>
>   - Tom
>
>  
>  Thanks!
>
>  JJ Zolper
>
> On Tuesday, August 28, 2012 2:24:03 AM UTC-4, Melvyn Sopacua wrote: 
>>
>> On 28-8-2012 6:58, JJ Zolper wrote: 
>>
>> > My problem is that I want each contributor to have their own separate 
>> page. 
>> > So if the first guys name for some example is Mike Smith then if you 
>> were 
>> > to click his name for example you would be sent to 
>> > /about/contributor/mikesmith and so on. 
>>
>> <
>> https://docs.djangoproject.com/en/1.4/ref/models/instances/#django.db.models.Model.get_absolute_url>
>>  
>>
>> and make sure you read the permalink bit. 
>> -- 
>> Melvyn Sopacua 
>>
>  -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/uFK1RTmzm5MJ.
> To post to this group, send email to django...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> django-users...@googlegroups.com .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>  

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Hi Dennis
Thanks for summarizing the contents of the mails.
Do you foresee any problems with the Model Inheritance scheme? At my end I
am stuck at getting a way to achieve dynamic polymorphism - which is
probably because I am new to Python.

I can create a new subclass for every Department I add. manage.py syncdb
creates the new table for every new department I add. Now I want to write
the application logic agnostic of the specific department. I want to load
the appropriate subclass dynamically at runtime. I haven't been able to do
this right now.
I can afford to create a new subclass everytime and run manage.py syndb
after that but cannot rewrite all the application logic all over again.

I feel given the subclass name there should be an easy way in python to get
the subclass itself which I should use for the current user.

At this point I should also mention there are a set of about 5-6 tables
(department being just one example) that I need to replicate for each new
department. I am thinking of doing it all via subclassing. That is I would
need to load as many subclass objects dynamically given the name of the
department.
If I can get the set of subclasses to use with a not too ugly looking code
is it still a terrible idea?

Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 9:34 PM, Dennis Lee Bieber wrote:

> On Fri, 21 Sep 2012 17:54:06 -0400, Rohit Banga
>  declaimed the following in
> gmane.comp.python.django.user:
>
> > Thanks Nikolas. I think my example was not clear.
> >
> > But all the code is shared between the departments (another reason for
> you
> > to say use the same tables!).
> > I do not need to have the explicit department name in the code. I don't
> > know the name of the departments yet! (It is just a metaphor)
> > I just want to add behavior like PhysicsDepartment.objects.filter() or
> > create(), save()  anywhere I want.
> > I want to work with the base class while loading the data from the
> subclass
> > at runtime. Simple polymorphism but with different database tables in the
> > backend.
> >
>
> I expect that over 95% of the responses will all emphasize using
> single set of tables, and a filter by the department (which is retrieved
> from the log-in authorization information)
>
> Anything else means you have to somehow dynamically:
>
> 1)  use one database for authorization and; somehow OPEN a department
> database connection that the models will hook into instead of using a
> "load-time" database. That probably means you have to replace the Django
> database connection system with one that you call at run-time. IOW, you
> do not have a database configured in the normal manner -- but EVERY
> Django function that issues an SQL operation would have to do something
> like:
>
> if not dbConnection:
> dbName = authuserdepartmentname
> dbConnection = whateverapi(database=dbName,...)
>
> where dbConnection is whatever Django normally uses to track the
> database connection.
>
>
> 2)  not use Django models defined at build time (ie, in code), but
> dynamically build the models at run-time so that you can specify the
> table name when accessed (sort of using code templates into which you
> substitute the needed table names which are then imported later -- good
> luck getting Django to recognize the validity of the models).
>
>
> 3)  operate separate "servers" for each department. Each server would
> have its own location for datafiles, but you can probably share the
> application code via soft-links or maybe even one shared code directory.
> This is workable for those databases that allow connections defined by
> file name/path (SQLite, embedded Firebird) but not for those using a
> dedicated database server (MySQL, PostgreSQL) -- because the file "name"
> will be fixed, but the data path would be relative to the "web server"
> URL. Of course, if you have many departments, you end up with many
> "servers" on different ports:
>
> http://server.localhost:8080/   Physics
> http://server.localhost:8081/   Mathematics
>
> or your server on port 80 rewrites URLs
>
> http://physics.server.localhost/ => server.localhost:8080
> http://mathematics.server.localhost/ => server.localhost:8081
> or
> http://physics.server.localhost/ =>
> http://server.localhost/physics
>
> where the directory structure is something like
>
> physics/
> app1-> softlink to  common/app1
> data/
> sqlite.db
>
> mathematics/
> app1-> softlink to  common/app1
> data/
> sqlite.db
>
> and the path to the database is relative
>
> ./data/sqlite.db
>
>
> Option 1 is probably easier to create, since the table names don't
> change -- only the "department" database name changes. Creating the
> database for each new department means over-riding the admin 

What's the best way to save generated images?

2012-09-21 Thread JC Briar
I'm writing an app that will generate, store, and display chart images. The 
idea is this: When a site visitor requests a given chart image, the app 
will check to see if it already exists. If not, the app will generate and 
store the necessary image before displaying it.

Towards that end, I have a Chart model with an ImageField:

class Chart(models.Model):
  pattern = models.ForeignKey(Pattern)
  symbols = models.BooleanField()
  rguides = models.BooleanField('row guides')
  cguides = models.BooleanField('column guides')
  hreps = models.SmallIntegerField('horizontal repeats', choices = 
REPS_CHOICES)
  vreps = models.SmallIntegerField('vertical repeats', choices = 
REPS_CHOICES)
  image = models.ImageField(upload_to = 'charts/%Y/%m')

So far, so good. From the admin interface, I and view my Charts and upload 
image files.

Here's my question: What's the best way of saving images that I generate? 
>From what I've read, it seems that my only choice is to create a temporary 
file, wrap it in a ImageFile object, use it in the construction of a new 
Chart, call save() on the chart, and delete the temporary file. But given 
that my image-generation code writes to any file-like object, this strikes 
me as inefficient. Is there any way to create an ImageFile object and 
retrieve from it a writable fobj?

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



HTTP_Authorization Striped

2012-09-21 Thread Christopher Hartfield
I am using Tastypie and I am trying to use their ApiKey Authentication 
method.  When send a curl post to my api the HTTP_Authorization header is 
sent correctly, however when I look at the request.META dictionary I notice 
that the HTTP_Authorization has been stripped.

I am using uWSGI and Nagios for this, not mod_wsgi (which I know has this 
problem)

Any ideas why?

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Thanks Nikolas. I think my example was not clear.

But all the code is shared between the departments (another reason for you
to say use the same tables!).
I do not need to have the explicit department name in the code. I don't
know the name of the departments yet! (It is just a metaphor)
I just want to add behavior like PhysicsDepartment.objects.filter() or
create(), save()  anywhere I want.
I want to work with the base class while loading the data from the subclass
at runtime. Simple polymorphism but with different database tables in the
backend.

Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 4:55 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  If I understand correctly, that's not the type of dynamic loading you
> need. That statement can be the much simpler:
>
> >>> from mysite.departments.form import getDepartment
>
> Rather, if you need models (tables) mapped to users at runtime, you need
> to load the *those* dynamically (normally you would define the model in
> your code, which includes--either implicitly or explicitly--the table name).
>
> At the risk of sounding like a broken record: simpler is better, and
> multiple, dynamically loaded models with the same schema is *not* simple
> ;)
>
> _Nik
>
>
> On 9/21/2012 1:43 PM, Rohit Banga wrote:
>
> Sure Nikolas I will reconsider your solution.
> In case I go for model inheritance then can I use the following solution
> to load the class dynamically?
>
> mod = __import__('mysite.departments', fromlist=[form.getDepartment()])
>
>
> klass = getattr(mod, 'form.getDepartment()')
>
>
>  Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Fri, Sep 21, 2012 at 4:33 PM, Nikolas Stevenson-Molnar <
> nik.mol...@consbio.org> wrote:
>
>>  I would still argue that the best solution is to use a robust
>> permissions model which would preclude this. Wherever there is code, you
>> invariably have the potential for security flaws. The more complicated you
>> make that code, the more chances for mistakes. On the other hand, simpler
>> code with well-defined methods for data access (e.g., maybe you never use
>> MyModel.objects, but rather have a custom function for filtering objects
>> based on permissions constraints; then you only have to ensure security in
>> one place) make for fewer mistakes and a code base which is easier to
>> maintain.
>>
>> _Nik
>>
>>
>> On 9/21/2012 12:26 PM, Rohit Banga wrote:
>>
>>
>>  I don't want to filter rows by "userid" since one place we forget the
>> filter in the code and there is an unauthorized data access.
>>
>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Nikolas Stevenson-Molnar
If I understand correctly, that's not the type of dynamic loading you
need. That statement can be the much simpler:

>>> from mysite.departments.form import getDepartment

Rather, if you need models (tables) mapped to users at runtime, you need
to load the /those/ dynamically (normally you would define the model in
your code, which includes--either implicitly or explicitly--the table name).

At the risk of sounding like a broken record: simpler is better, and
multiple, dynamically loaded models with the same schema is /not/ simple ;)

_Nik

On 9/21/2012 1:43 PM, Rohit Banga wrote:
> Sure Nikolas I will reconsider your solution.
> In case I go for model inheritance then can I use the following
> solution to load the class dynamically?
> |mod = __import__('mysite.departments', fromlist=[form.getDepartment()])
>
>
> klass = getattr(mod, 'form.getDepartment()|')
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Fri, Sep 21, 2012 at 4:33 PM, Nikolas Stevenson-Molnar
> > wrote:
>
> I would still argue that the best solution is to use a robust
> permissions model which would preclude this. Wherever there is
> code, you invariably have the potential for security flaws. The
> more complicated you make that code, the more chances for
> mistakes. On the other hand, simpler code with well-defined
> methods for data access (e.g., maybe you never use
> MyModel.objects, but rather have a custom function for filtering
> objects based on permissions constraints; then you only have to
> ensure security in one place) make for fewer mistakes and a code
> base which is easier to maintain.
>
> _Nik
>
>
> On 9/21/2012 12:26 PM, Rohit Banga wrote:
>>
>> I don't want to filter rows by "userid" since one place we forget
>> the filter in the code and there is an unauthorized data access.
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Sure Nikolas I will reconsider your solution.
In case I go for model inheritance then can I use the following solution to
load the class dynamically?

mod = __import__('mysite.departments', fromlist=[form.getDepartment()])

klass = getattr(mod, 'form.getDepartment()')


Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 4:33 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  I would still argue that the best solution is to use a robust permissions
> model which would preclude this. Wherever there is code, you invariably
> have the potential for security flaws. The more complicated you make that
> code, the more chances for mistakes. On the other hand, simpler code with
> well-defined methods for data access (e.g., maybe you never use
> MyModel.objects, but rather have a custom function for filtering objects
> based on permissions constraints; then you only have to ensure security in
> one place) make for fewer mistakes and a code base which is easier to
> maintain.
>
> _Nik
>
>
> On 9/21/2012 12:26 PM, Rohit Banga wrote:
>
>
>  I don't want to filter rows by "userid" since one place we forget the
> filter in the code and there is an unauthorized data access.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Sounds good Joel... Thanks.
What if I want to dynamically create the object of the subclass so that I
don't have to duplicate the code.

If I have

class Department(models.Model):
someField =...

class PhysicsDepartment(Department):
 pass

Then how do I instantiate the objects dynamically so I do not have to do
Department.objects.filter()
PhysicsDepartment.objects.filter()

I want to share the same code for all departments. Can I instantiate them
dynamically given that I have the string name and the module name available
in a dictionary.


Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 4:16 PM, Joel Goldstick wrote:

> On Fri, Sep 21, 2012 at 4:05 PM, Rohit Banga 
> wrote:
> > I just saw this example:
> >
> http://django.readthedocs.org/en/1.4/topics/db/models.html#multi-table-inheritance
> >
> > Since it is possible for me to have a few number of users (now called
> > departments), I can define a create a python file which subclasses all
> the
> > models and then run syncdb to update the database for creating the new
> > tables.
> > But what is different is I need to fetch the Place subclass (eg.
> Restaurant
> > or School page above) at runtime based on the logged in user. Assuming I
> > have a map from id to class name can I just load it dynamically?
> >
> > Thanks
> > Rohit Banga
> > http://iamrohitbanga.com/
> >
> >
> > On Fri, Sep 21, 2012 at 3:26 PM, Rohit Banga 
> > wrote:
> >>
> >> Thanks for your comments. I agree that technically it is feasible to
> >> achieve the same affect with row level permissions or filtering the
> rows by
> >> user.
> >> The requirement is to keep the data separate using different tables,
> >> databases while still using the same model. May be user is not the right
> >> metaphor to use here. Lets just "imagine" that we have the same schema
> to
> >> use for different departments in a college but one department does not
> want
> >> to house their data in the same tables as another department.
> >>
> >> I don't want to filter rows by "userid" since one place we forget the
> >> filter in the code and there is an unauthorized data access.
> >>
> >> I will look into dynamic models though I am not sure if it is well
> >> supported.
> >> What about routing to different databases based on user id?
> >>
> >> Thanks
> >> Rohit Banga
> >> http://iamrohitbanga.com/
> >>
> >>
> >>
> >> On Fri, Sep 21, 2012 at 2:34 PM, Joel Goldstick <
> joel.goldst...@gmail.com>
> >> wrote:
> >>>
> >>> On Fri, Sep 21, 2012 at 2:30 PM, Nikolas Stevenson-Molnar
> >>>  wrote:
> >>> > If you absolutely have to use separate tables per user (again, I do
> not
> >>> > recommend this), then you'll need to implement some form of dynamic
> >>> > models
> >>> > (models which can be constructed at run-time rather than needing to
> be
> >>> > defined in the application code) such as discussed here:
> >>> > https://code.djangoproject.com/wiki/DynamicModels (see link at the
> top
> >>> > of
> >>> > the page for newer approaches and full implementations of dynamic
> >>> > models).
> >>> >
> >>> >
> >>> > _Nik
> >>> >
> >>> > On 9/21/2012 11:07 AM, Rohit Banga wrote:
> >>> >
> >>> > Just HAVE to separate data - requirement.
> >>> >
> >>> > On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee" 
> wrote:
> >>> >>
> >>> >> As I understand it: (And im fairly new to django too)
> >>> >>
> >>> >> A model corresponds to a single table (not multiple).
> >>> >> The question to you is what is different between User1 and User2
> that
> >>> >> you
> >>> >> need different tables?
> >>> >>
> >>> >>
> >>> >>
> >>> >> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga <
> iamrohitba...@gmail.com>
> >>> >> wrote:
> >>> >>>
> >>> >>> Hi
> >>> >>>
> >>> >>> I am a django #n00b. I came across the django model documentation
> and
> >>> >>> found it pretty interesting.
> >>> >>> (https://docs.djangoproject.com/en/dev/topics/db/models/).
> >>> >>>
> >>> >>> Now my usecase requires I have a set of Models and each model has
> >>> >>> multiple tables corresponding to it.
> >>> >>> For example when user1 registers I can create a table user1_t1,
> >>> >>> user1_t2,
> >>> >>> user1_t3.
> >>> >>> When user2 registers I can create a table user2_t1, user2_t2,
> >>> >>> user2_t3.
> >>> >>>
> >>> >>> I really like the Model abstraction but can't find a way to create
> >>> >>> these
> >>> >>> multiple tables conveniently without creating new models. I could
> not
> >>> >>> find
> >>> >>> clear solutions to this on the internet.
> >>> >>> I just want clear separation between t1, t2, t3 for the all users.
> >>> >>> Depending on the logged in user, I want to use the relevant table.
> >>> >>> What is
> >>> >>> the cleanest way to achieve this with Django?
> >>> >>>
> >>> >>> If it is not possible to do this with tables I can think about
> >>> >>> different
> >>> >>> databases one for each user with the same set of tables. 

Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Nikolas Stevenson-Molnar
I would still argue that the best solution is to use a robust
permissions model which would preclude this. Wherever there is code, you
invariably have the potential for security flaws. The more complicated
you make that code, the more chances for mistakes. On the other hand,
simpler code with well-defined methods for data access (e.g., maybe you
never use MyModel.objects, but rather have a custom function for
filtering objects based on permissions constraints; then you only have
to ensure security in one place) make for fewer mistakes and a code base
which is easier to maintain.

_Nik

On 9/21/2012 12:26 PM, Rohit Banga wrote:
>
> I don't want to filter rows by "userid" since one place we forget the
> filter in the code and there is an unauthorized data access.

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Joel Goldstick
On Fri, Sep 21, 2012 at 4:05 PM, Rohit Banga  wrote:
> I just saw this example:
> http://django.readthedocs.org/en/1.4/topics/db/models.html#multi-table-inheritance
>
> Since it is possible for me to have a few number of users (now called
> departments), I can define a create a python file which subclasses all the
> models and then run syncdb to update the database for creating the new
> tables.
> But what is different is I need to fetch the Place subclass (eg. Restaurant
> or School page above) at runtime based on the logged in user. Assuming I
> have a map from id to class name can I just load it dynamically?
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Fri, Sep 21, 2012 at 3:26 PM, Rohit Banga 
> wrote:
>>
>> Thanks for your comments. I agree that technically it is feasible to
>> achieve the same affect with row level permissions or filtering the rows by
>> user.
>> The requirement is to keep the data separate using different tables,
>> databases while still using the same model. May be user is not the right
>> metaphor to use here. Lets just "imagine" that we have the same schema to
>> use for different departments in a college but one department does not want
>> to house their data in the same tables as another department.
>>
>> I don't want to filter rows by "userid" since one place we forget the
>> filter in the code and there is an unauthorized data access.
>>
>> I will look into dynamic models though I am not sure if it is well
>> supported.
>> What about routing to different databases based on user id?
>>
>> Thanks
>> Rohit Banga
>> http://iamrohitbanga.com/
>>
>>
>>
>> On Fri, Sep 21, 2012 at 2:34 PM, Joel Goldstick 
>> wrote:
>>>
>>> On Fri, Sep 21, 2012 at 2:30 PM, Nikolas Stevenson-Molnar
>>>  wrote:
>>> > If you absolutely have to use separate tables per user (again, I do not
>>> > recommend this), then you'll need to implement some form of dynamic
>>> > models
>>> > (models which can be constructed at run-time rather than needing to be
>>> > defined in the application code) such as discussed here:
>>> > https://code.djangoproject.com/wiki/DynamicModels (see link at the top
>>> > of
>>> > the page for newer approaches and full implementations of dynamic
>>> > models).
>>> >
>>> >
>>> > _Nik
>>> >
>>> > On 9/21/2012 11:07 AM, Rohit Banga wrote:
>>> >
>>> > Just HAVE to separate data - requirement.
>>> >
>>> > On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  wrote:
>>> >>
>>> >> As I understand it: (And im fairly new to django too)
>>> >>
>>> >> A model corresponds to a single table (not multiple).
>>> >> The question to you is what is different between User1 and User2 that
>>> >> you
>>> >> need different tables?
>>> >>
>>> >>
>>> >>
>>> >> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga 
>>> >> wrote:
>>> >>>
>>> >>> Hi
>>> >>>
>>> >>> I am a django #n00b. I came across the django model documentation and
>>> >>> found it pretty interesting.
>>> >>> (https://docs.djangoproject.com/en/dev/topics/db/models/).
>>> >>>
>>> >>> Now my usecase requires I have a set of Models and each model has
>>> >>> multiple tables corresponding to it.
>>> >>> For example when user1 registers I can create a table user1_t1,
>>> >>> user1_t2,
>>> >>> user1_t3.
>>> >>> When user2 registers I can create a table user2_t1, user2_t2,
>>> >>> user2_t3.
>>> >>>
>>> >>> I really like the Model abstraction but can't find a way to create
>>> >>> these
>>> >>> multiple tables conveniently without creating new models. I could not
>>> >>> find
>>> >>> clear solutions to this on the internet.
>>> >>> I just want clear separation between t1, t2, t3 for the all users.
>>> >>> Depending on the logged in user, I want to use the relevant table.
>>> >>> What is
>>> >>> the cleanest way to achieve this with Django?
>>> >>>
>>> >>> If it is not possible to do this with tables I can think about
>>> >>> different
>>> >>> databases one for each user with the same set of tables. Is it
>>> >>> possible to
>>> >>> do the same with multiple databases?
>>> >>>
>>> >>> Thanks
>>> >>> Rohit Banga
>>> >>> --
>>>
>>> Why not add a user as a field in your models.  Then, when the user
>>> logs in, make sure the queries filter only that user's data
>>>
>>> --
>>> Joel Goldstick
>>>
>>> --
Look here: 
https://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance

You can create your model as an abstract model.  Then subclass it for
each department.  Since you say your model will be identical, there is
really no code to write except to create each subclassed model.  Run
syncdb and you will see all of your  department models.

-- 
Joel Goldstick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 

Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
I just saw this example:
http://django.readthedocs.org/en/1.4/topics/db/models.html#multi-table-inheritance

Since it is possible for me to have a few number of users (now called
departments), I can define a create a python file which subclasses all the
models and then run syncdb to update the database for creating the new
tables.
But what is different is I need to fetch the Place subclass (eg. Restaurant
or School page above) at runtime based on the logged in user. Assuming I
have a map from id to class name can I just load it dynamically?

Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 3:26 PM, Rohit Banga wrote:

> Thanks for your comments. I agree that technically it is feasible to
> achieve the same affect with row level permissions or filtering the rows by
> user.
> The requirement is to keep the data separate using different tables,
> databases while still using the same model. May be user is not the right
> metaphor to use here. Lets just "imagine" that we have the same schema to
> use for different departments in a college but one department does not want
> to house their data in the same tables as another department.
>
> I don't want to filter rows by "userid" since one place we forget the
> filter in the code and there is an unauthorized data access.
>
> I will look into dynamic models though I am not sure if it is well
> supported.
> What about routing to different databases based on user id?
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
>
> On Fri, Sep 21, 2012 at 2:34 PM, Joel Goldstick 
> wrote:
>
>> On Fri, Sep 21, 2012 at 2:30 PM, Nikolas Stevenson-Molnar
>>  wrote:
>> > If you absolutely have to use separate tables per user (again, I do not
>> > recommend this), then you'll need to implement some form of dynamic
>> models
>> > (models which can be constructed at run-time rather than needing to be
>> > defined in the application code) such as discussed here:
>> > https://code.djangoproject.com/wiki/DynamicModels (see link at the top
>> of
>> > the page for newer approaches and full implementations of dynamic
>> models).
>> >
>> >
>> > _Nik
>> >
>> > On 9/21/2012 11:07 AM, Rohit Banga wrote:
>> >
>> > Just HAVE to separate data - requirement.
>> >
>> > On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  wrote:
>> >>
>> >> As I understand it: (And im fairly new to django too)
>> >>
>> >> A model corresponds to a single table (not multiple).
>> >> The question to you is what is different between User1 and User2 that
>> you
>> >> need different tables?
>> >>
>> >>
>> >>
>> >> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga 
>> >> wrote:
>> >>>
>> >>> Hi
>> >>>
>> >>> I am a django #n00b. I came across the django model documentation and
>> >>> found it pretty interesting.
>> >>> (https://docs.djangoproject.com/en/dev/topics/db/models/).
>> >>>
>> >>> Now my usecase requires I have a set of Models and each model has
>> >>> multiple tables corresponding to it.
>> >>> For example when user1 registers I can create a table user1_t1,
>> user1_t2,
>> >>> user1_t3.
>> >>> When user2 registers I can create a table user2_t1, user2_t2,
>> user2_t3.
>> >>>
>> >>> I really like the Model abstraction but can't find a way to create
>> these
>> >>> multiple tables conveniently without creating new models. I could not
>> find
>> >>> clear solutions to this on the internet.
>> >>> I just want clear separation between t1, t2, t3 for the all users.
>> >>> Depending on the logged in user, I want to use the relevant table.
>> What is
>> >>> the cleanest way to achieve this with Django?
>> >>>
>> >>> If it is not possible to do this with tables I can think about
>> different
>> >>> databases one for each user with the same set of tables. Is it
>> possible to
>> >>> do the same with multiple databases?
>> >>>
>> >>> Thanks
>> >>> Rohit Banga
>> >>> --
>>
>> Why not add a user as a field in your models.  Then, when the user
>> logs in, make sure the queries filter only that user's data
>>
>> --
>> Joel Goldstick
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Thanks for your comments. I agree that technically it is feasible to
achieve the same affect with row level permissions or filtering the rows by
user.
The requirement is to keep the data separate using different tables,
databases while still using the same model. May be user is not the right
metaphor to use here. Lets just "imagine" that we have the same schema to
use for different departments in a college but one department does not want
to house their data in the same tables as another department.

I don't want to filter rows by "userid" since one place we forget the
filter in the code and there is an unauthorized data access.

I will look into dynamic models though I am not sure if it is well
supported.
What about routing to different databases based on user id?

Thanks
Rohit Banga
http://iamrohitbanga.com/


On Fri, Sep 21, 2012 at 2:34 PM, Joel Goldstick wrote:

> On Fri, Sep 21, 2012 at 2:30 PM, Nikolas Stevenson-Molnar
>  wrote:
> > If you absolutely have to use separate tables per user (again, I do not
> > recommend this), then you'll need to implement some form of dynamic
> models
> > (models which can be constructed at run-time rather than needing to be
> > defined in the application code) such as discussed here:
> > https://code.djangoproject.com/wiki/DynamicModels (see link at the top
> of
> > the page for newer approaches and full implementations of dynamic
> models).
> >
> >
> > _Nik
> >
> > On 9/21/2012 11:07 AM, Rohit Banga wrote:
> >
> > Just HAVE to separate data - requirement.
> >
> > On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  wrote:
> >>
> >> As I understand it: (And im fairly new to django too)
> >>
> >> A model corresponds to a single table (not multiple).
> >> The question to you is what is different between User1 and User2 that
> you
> >> need different tables?
> >>
> >>
> >>
> >> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga 
> >> wrote:
> >>>
> >>> Hi
> >>>
> >>> I am a django #n00b. I came across the django model documentation and
> >>> found it pretty interesting.
> >>> (https://docs.djangoproject.com/en/dev/topics/db/models/).
> >>>
> >>> Now my usecase requires I have a set of Models and each model has
> >>> multiple tables corresponding to it.
> >>> For example when user1 registers I can create a table user1_t1,
> user1_t2,
> >>> user1_t3.
> >>> When user2 registers I can create a table user2_t1, user2_t2, user2_t3.
> >>>
> >>> I really like the Model abstraction but can't find a way to create
> these
> >>> multiple tables conveniently without creating new models. I could not
> find
> >>> clear solutions to this on the internet.
> >>> I just want clear separation between t1, t2, t3 for the all users.
> >>> Depending on the logged in user, I want to use the relevant table.
> What is
> >>> the cleanest way to achieve this with Django?
> >>>
> >>> If it is not possible to do this with tables I can think about
> different
> >>> databases one for each user with the same set of tables. Is it
> possible to
> >>> do the same with multiple databases?
> >>>
> >>> Thanks
> >>> Rohit Banga
> >>> --
>
> Why not add a user as a field in your models.  Then, when the user
> logs in, make sure the queries filter only that user's data
>
> --
> Joel Goldstick
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Joel Goldstick
On Fri, Sep 21, 2012 at 2:30 PM, Nikolas Stevenson-Molnar
 wrote:
> If you absolutely have to use separate tables per user (again, I do not
> recommend this), then you'll need to implement some form of dynamic models
> (models which can be constructed at run-time rather than needing to be
> defined in the application code) such as discussed here:
> https://code.djangoproject.com/wiki/DynamicModels (see link at the top of
> the page for newer approaches and full implementations of dynamic models).
>
>
> _Nik
>
> On 9/21/2012 11:07 AM, Rohit Banga wrote:
>
> Just HAVE to separate data - requirement.
>
> On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  wrote:
>>
>> As I understand it: (And im fairly new to django too)
>>
>> A model corresponds to a single table (not multiple).
>> The question to you is what is different between User1 and User2 that you
>> need different tables?
>>
>>
>>
>> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga 
>> wrote:
>>>
>>> Hi
>>>
>>> I am a django #n00b. I came across the django model documentation and
>>> found it pretty interesting.
>>> (https://docs.djangoproject.com/en/dev/topics/db/models/).
>>>
>>> Now my usecase requires I have a set of Models and each model has
>>> multiple tables corresponding to it.
>>> For example when user1 registers I can create a table user1_t1, user1_t2,
>>> user1_t3.
>>> When user2 registers I can create a table user2_t1, user2_t2, user2_t3.
>>>
>>> I really like the Model abstraction but can't find a way to create these
>>> multiple tables conveniently without creating new models. I could not find
>>> clear solutions to this on the internet.
>>> I just want clear separation between t1, t2, t3 for the all users.
>>> Depending on the logged in user, I want to use the relevant table. What is
>>> the cleanest way to achieve this with Django?
>>>
>>> If it is not possible to do this with tables I can think about different
>>> databases one for each user with the same set of tables. Is it possible to
>>> do the same with multiple databases?
>>>
>>> Thanks
>>> Rohit Banga
>>> --

Why not add a user as a field in your models.  Then, when the user
logs in, make sure the queries filter only that user's data

-- 
Joel Goldstick

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Nikolas Stevenson-Molnar
If you /absolutely/ have to use separate tables per user (again, I do
not recommend this), then you'll need to implement some form of dynamic
models (models which can be constructed at run-time rather than needing
to be defined in the application code) such as discussed here:
https://code.djangoproject.com/wiki/DynamicModels (see link at the top
of the page for newer approaches and full implementations of dynamic
models).

_Nik

On 9/21/2012 11:07 AM, Rohit Banga wrote:
>
> Just HAVE to separate data - requirement.
>
> On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  > wrote:
>
> As I understand it: (And im fairly new to django too)
>
> A model corresponds to a single table (not multiple).
> The question to you is what is different between User1 and User2
> that you need different tables?
>
>
>
> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga
> > wrote:
>
> Hi
>
> I am a django #n00b. I came across the django model
> documentation and found it pretty interesting.
> (https://docs.djangoproject.com/en/dev/topics/db/models/).
>
> Now my usecase requires I have a set of Models and each model
> has multiple tables corresponding to it.
> For example when user1 registers I can create a table
> user1_t1, user1_t2, user1_t3.
> When user2 registers I can create a table user2_t1, user2_t2,
> user2_t3.
>
> I really like the Model abstraction but can't find a way to
> create these multiple tables conveniently without creating new
> models. I could not find clear solutions to this on the internet.
> I just want clear separation between t1, t2, t3 for the all
> users. Depending on the logged in user, I want to use the
> relevant table. What is the cleanest way to achieve this with
> Django?
>
> If it is not possible to do this with tables I can think about
> different databases one for each user with the same set of
> tables. Is it possible to do the same with multiple databases?
>
> Thanks
> Rohit Banga
> -- 
> You received this message because you are subscribed to the
> Google Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/tl8qKhJb-_cJ.
> To post to this group, send email to
> django-users@googlegroups.com
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
> -- 
> Mayukh Mukherjee
> http://www.linkedin.com/in/mayukhmmukherjee
>
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Nikolas Stevenson-Molnar
If I understand correctly, what you really need is object (or row) level
permissions. It doesn't make a lot of sense to create a table for each
user, especially when the data model is exactly the same (and could get
you a huge, messy database really quick). Rather, what you want to
control is the /access/ to that data. E.g., all data is stored in the
same table, but user 1 can access objects (rows) 1, 2, 3 but not 4, 5, 6
and user 2 can access 4, 5, 6, but not 1, 2, 3.

Maybe take a look at
http://pypi.python.org/pypi/django-object-permissions. I haven't used
it, but it seems to address this issue. Or roll your own object
permission model. It's conceptually quite simple: create a permissions
model/table with a foreign key relationship to your other model. The
permission model should record the user, the object, and (optionally)
what level of permission they have to that object (read,write,etc.)

_Nik

On 9/21/2012 11:07 AM, Rohit Banga wrote:
>
> Just HAVE to separate data - requirement.
>
> On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  > wrote:
>
> As I understand it: (And im fairly new to django too)
>
> A model corresponds to a single table (not multiple).
> The question to you is what is different between User1 and User2
> that you need different tables?
>
>
>
> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga
> > wrote:
>
> Hi
>
> I am a django #n00b. I came across the django model
> documentation and found it pretty interesting.
> (https://docs.djangoproject.com/en/dev/topics/db/models/).
>
> Now my usecase requires I have a set of Models and each model
> has multiple tables corresponding to it.
> For example when user1 registers I can create a table
> user1_t1, user1_t2, user1_t3.
> When user2 registers I can create a table user2_t1, user2_t2,
> user2_t3.
>
> I really like the Model abstraction but can't find a way to
> create these multiple tables conveniently without creating new
> models. I could not find clear solutions to this on the internet.
> I just want clear separation between t1, t2, t3 for the all
> users. Depending on the logged in user, I want to use the
> relevant table. What is the cleanest way to achieve this with
> Django?
>
> If it is not possible to do this with tables I can think about
> different databases one for each user with the same set of
> tables. Is it possible to do the same with multiple databases?
>
> Thanks
> Rohit Banga
> -- 
> You received this message because you are subscribed to the
> Google Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/tl8qKhJb-_cJ.
> To post to this group, send email to
> django-users@googlegroups.com
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
> -- 
> Mayukh Mukherjee
> http://www.linkedin.com/in/mayukhmmukherjee
>
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Just HAVE to separate data - requirement.
On Sep 21, 2012 1:59 PM, "Mayukh Mukherjee"  wrote:

> As I understand it: (And im fairly new to django too)
>
> A model corresponds to a single table (not multiple).
> The question to you is what is different between User1 and User2 that you
> need different tables?
>
>
>
> On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga wrote:
>
>> Hi
>>
>> I am a django #n00b. I came across the django model documentation and
>> found it pretty interesting. (
>> https://docs.djangoproject.com/en/dev/topics/db/models/).
>>
>> Now my usecase requires I have a set of Models and each model has
>> multiple tables corresponding to it.
>> For example when user1 registers I can create a table user1_t1, user1_t2,
>> user1_t3.
>> When user2 registers I can create a table user2_t1, user2_t2, user2_t3.
>>
>> I really like the Model abstraction but can't find a way to create these
>> multiple tables conveniently without creating new models. I could not find
>> clear solutions to this on the internet.
>> I just want clear separation between t1, t2, t3 for the all users.
>> Depending on the logged in user, I want to use the relevant table. What is
>> the cleanest way to achieve this with Django?
>>
>> If it is not possible to do this with tables I can think about different
>> databases one for each user with the same set of tables. Is it possible to
>> do the same with multiple databases?
>>
>> Thanks
>> Rohit Banga
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/tl8qKhJb-_cJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Mayukh Mukherjee
> http://www.linkedin.com/in/mayukhmmukherjee
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to separate data having the same model but belonging to different users?

2012-09-21 Thread Mayukh Mukherjee
As I understand it: (And im fairly new to django too)

A model corresponds to a single table (not multiple).
The question to you is what is different between User1 and User2 that you
need different tables?



On Fri, Sep 21, 2012 at 1:35 PM, Rohit Banga wrote:

> Hi
>
> I am a django #n00b. I came across the django model documentation and
> found it pretty interesting. (
> https://docs.djangoproject.com/en/dev/topics/db/models/).
>
> Now my usecase requires I have a set of Models and each model has multiple
> tables corresponding to it.
> For example when user1 registers I can create a table user1_t1, user1_t2,
> user1_t3.
> When user2 registers I can create a table user2_t1, user2_t2, user2_t3.
>
> I really like the Model abstraction but can't find a way to create these
> multiple tables conveniently without creating new models. I could not find
> clear solutions to this on the internet.
> I just want clear separation between t1, t2, t3 for the all users.
> Depending on the logged in user, I want to use the relevant table. What is
> the cleanest way to achieve this with Django?
>
> If it is not possible to do this with tables I can think about different
> databases one for each user with the same set of tables. Is it possible to
> do the same with multiple databases?
>
> Thanks
> Rohit Banga
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/tl8qKhJb-_cJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Mayukh Mukherjee
http://www.linkedin.com/in/mayukhmmukherjee

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



custom upload handlers

2012-09-21 Thread Michael P. Soulier
Looking at the docs...

https://docs.djangoproject.com/en/1.4/topics/http/file-uploads/

under "Modifying upload handlers on the fly"

it states:

"Sometimes particular views require different upload behavior. In these cases,
you can override upload handlers on a per-request basis by modifying
request.upload_handlers. By default, this list will contain the upload
handlers given by FILE_UPLOAD_HANDLERS, but you can modify the list as you
would any other list.

For instance, suppose you've written a ProgressBarUploadHandler that provides
feedback on upload progress to some sort of AJAX widget. You'd add this
handler to your upload handlers like this:

request.upload_handlers.insert(0, ProgressBarUploadHandler())

You'd probably want to use list.insert() in this case (instead of append())
because a progress bar handler would need to run before any other handlers.
Remember, the upload handlers are processed in order.

If you want to replace the upload handlers completely, you can just assign a
new list:

request.upload_handlers = [ProgressBarUploadHandler()]"

If I try this, at the top of my view function, 

request.upload_handlers = [McdFileUploadHandler()]

then the upload happens first, and I get an exception:

"You cannot set the upload handlers after the upload has been processed."

Umm, how can I put this sooner? It's the first line of my view function.

Thanks,
Mike

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



How to separate data having the same model but belonging to different users?

2012-09-21 Thread Rohit Banga
Hi

I am a django #n00b. I came across the django model documentation and found 
it pretty interesting. (
https://docs.djangoproject.com/en/dev/topics/db/models/).

Now my usecase requires I have a set of Models and each model has multiple 
tables corresponding to it.
For example when user1 registers I can create a table user1_t1, user1_t2, 
user1_t3.
When user2 registers I can create a table user2_t1, user2_t2, user2_t3.

I really like the Model abstraction but can't find a way to create these 
multiple tables conveniently without creating new models. I could not find 
clear solutions to this on the internet.
I just want clear separation between t1, t2, t3 for the all users. 
Depending on the logged in user, I want to use the relevant table. What is 
the cleanest way to achieve this with Django?

If it is not possible to do this with tables I can think about different 
databases one for each user with the same set of tables. Is it possible to 
do the same with multiple databases?

Thanks
Rohit Banga

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



Re: reduce number of DB-Queries

2012-09-21 Thread kloetpatra
I think aggregation can't be used because the calculations are  a bit more 
complex than just the sum/average/count/min/max of one field.

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



mod_wsgi and url resolve (so confused, please help)

2012-09-21 Thread The Bear
Hi All

I am really stuck with resolving urls now i have moved my app to mod_wsgi 
environment.

Basically my problem is that when using a mod wsgi prefix valid urls will 
resolve in the usual general browsing way but not using teh resolve 
function directly

so
url = reverse('grant_and_save')

gives url as '/ethics/ethics/grantandsave/'

but when i do this https://mysite/ethics/ethics/grantandsave/ works just 
fine but

func, args, kwargs = resolve(url)

in my code gives the can't find page exception

{'path': 'ethics/ethics/grantandsave/', 'tried': [[, , 
, , ...

I'm really confused as i don't really understand mod_wsgi.

I tried putting in a FORCE_SCRIPT_NAME setting of '/ethics' and of 'ethics' 
but that didn't help at all. I also tried hard coding various options into 
resolve() with no luck

here are my files

in httpd conf

WSGIDaemonProcess  ethics_project processes=4 threads=1 
display-name=int_ethics_project inactivity-timeout=100 maximum-requests=1000

WSGIScriptAlias /ethics 
/srv/wsgi/intranetapps/virtualenvs/ETHICS_PROJECT/ethics_project/apache/django.wsgi

WSGIProcessGroup ethics_project
 

and in djang.wsgi

import os, sys
>
> from os.path import abspath, dirname, join

> import site

>
proj_root = abspath(join(dirname(__file__), '..'))

> major, minor = sys.version_info[:2] 

> ALLDIRS = ['%s/lib/python%s.%s/site-packages' %(root, major, minor)]

> # Remember original sys.path.

> prev_sys_path = list(sys.path)

> # Add each new site-packages directory.

> for directory in ALLDIRS:

>   site.addsitedir(directory)

> # Reorder sys.path so new directories at the front.

> new_sys_path = []

> for item in list(sys.path):

> if item not in prev_sys_path:

> new_sys_path.append(item)

> sys.path.remove(item)

> sys.path[:0] = new_sys_path

> sys.path.append(root)

> sys.path.append(proj_root)

> sys.path.append('%s/web2ldap' %proj_root)

> import django.core.handlers.wsgi

> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

> application = django.core.handlers.wsgi.WSGIHandler()

> import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()

root = abspath(join(dirname(__file__), '../..'))

urls.py (project)

urlpatterns = patterns('',

# Uncomment the next line to enable the admin:
url(r'^ethics/admin/', include(admin.site.urls), name="admin_home"),
(r'^ethics/', include('ethics.urls')),
)
urlpatterns += staticfiles_urlpatterns()

and ethics/urls.py the pattern

url(r'^grantandsave/$', grant_and_save, name="grant_and_save"),

which resolves just fine if i go to the page

https://mysite/ethics/ethics/grantandsave





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



webRTC videoconference demo

2012-09-21 Thread Kazmierczak Stéphane
Hello, 

I am looking for some advice, I am trying to adapt a videoconference demo 
app 
(link)
 
using webRTC to my Django website.
I read articles about webRTC and Django but I 
can't decide which technologies I should use (twisted, tornado, 
django-socketio, nodejs/redis... )   

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



Re: reduce number of DB-Queries

2012-09-21 Thread Stephen Anto
Hi,

Try to use Django aggregation,

example given on http://f2finterview.com/web/Django/14/ for Aggregation

On Fri, Sep 21, 2012 at 2:29 PM, kloetpatra  wrote:

> Hi!
> I have the following models:
>
> class Player(models.Model):
> name = models.CharField('Name', max_length=40)
>
> def __unicode__(self):
> return self.name
>
> def goals(self):
> g = 0
> ms = Match.objects.select_related().filter(
> Q(opp1=self)|Q(opp2=self) )
> for m in ms:
> if (m.opp1==self):
> g += m.opp1_goals
> else:
> g += m.opp2_goals
> return g
>
> def matches_won(self):
> ms = Match.objects.filter( (Q(opp1=self) &
> Q(opp1_goals__gt=F('opp2_goals'))) |
> (Q(opp2=self) & Q(opp2_goals__gt=F('opp1_goals'))) ).count()
> return ms
>
> def matches_draw(self):
> ms = Match.objects.filter( (Q(opp1=self) &
> Q(opp1_goals__exact=F('opp2_goals'))) |
> (Q(opp2=self) & Q(opp2_goals__exact=F('opp1_goals'))) ).count()
> return ms
>
> def match_points(self):
> p = 0
> p += 3 * self.matches_won()
> p += 1 * self.matches_draw()
> return p
>
> def matches_played(self):
> return Match.objects.filter(Q(opp1=self) | Q(opp2=self)).count()
>
>
> class Match(models.Model):
> class Meta:
> verbose_name_plural = "Matches"
> opp1 = models.ForeignKey(Player, related_name="player1")
> opp2 = models.ForeignKey(Player, related_name="player2")
> opp1_goals = models.IntegerField("Goals P1")
> opp2_goals = models.IntegerField("Goals P2")
>
> def __unicode__(self):
> return "%s %d:%d %s"%(self.opp1.name, self.opp1_goals,
> self.opp2_goals, self.opp2.name)
>
> My problem is when want to display overall player statistics I get about
> 1200 DB-Queries.
> This is because for each player there will be 5 Queries due to
> matches_won, matches_draw, goals, matches_played functions.
> How is it possible to retrieve those "calculated properties" without
> having so much queries?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/-ki6lNP0IDAJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Thanks & Regards
Stephen S



Website: www.f2finterview.com
Blog:  blog.f2finterview.com
Tutorial:  tutorial.f2finterview.com
Group:www.charvigroups.com

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



Re: url pattern matching

2012-09-21 Thread Stephen Anto
Hi

url('^paperforms/$',
'view.methods', name='paperforms'),
url('^paperforms/(\w+)/$',
'view.methods', name='paperforms_with_arguments'),

It will work if you make your urls like this

On Fri, Sep 21, 2012 at 7:57 PM, Brian Patterson wrote:

> Hi Everyone,
> I'm very new to Django and just trying to explore the basics.  I'm having
> a problem with the url pattern matching.  If i go to site:
> http://mysite:8000/paperforms/
>
> I get the following error:
>
> Using the URLconf defined in mysite.urls, Django tried these URL
> patterns, in this order:
>
>1. ^admin/
>2. ^paperforms/ ^paperforms/$
>3. ^paperforms/ ^paperforms/(?P\d+)/$
>4. ^paperforms/ ^paperforms/(?P\d+)/results/$
>5. ^paperforms/ ^paperforms/(?P\d+)/vote/$
>6. ^paperforms/ ^admin/
>
> The current URL, paperforms/, didn't match any of these.
>
> Shouldn't it find a match on line # 2.
>
> thanks for your help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/J4trVX-oH0AJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Thanks & Regards
Stephen S



Website: www.f2finterview.com
Blog:  blog.f2finterview.com
Tutorial:  tutorial.f2finterview.com
Group:www.charvigroups.com

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



Re: How often does Django need updates/patches?

2012-09-21 Thread Stephen Anto
Hi,

Try to use Django stable version which is available on Django projects
site. It is good practice.

On Fri, Sep 21, 2012 at 8:26 AM, Taylor Smith  wrote:

> Our new website is being built on Django and we are trying to figure out
> the easiest way to host and maintain the site.
> It seems there are a few managed hosting options like webfaction and
> heroku, but they will only handle the linux and database patches and
> updates.
>
> I am hoping to find out how often Django need to be updated. -- like every
> month? or more like one or twice a year?
> can a non-developer handle these updates or would we be better off hiring
> someone?
>
> any advice is much appreciated!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/bFVA65mLIFgJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Thanks & Regards
Stephen S



Website: www.f2finterview.com
Blog:  blog.f2finterview.com
Tutorial:  tutorial.f2finterview.com
Group:www.charvigroups.com

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



Re: Decorate 3rd party app's views

2012-09-21 Thread Garry Polley
Here is a more reusable way to do this:  https://gist.github.com/3762045

On Friday, September 21, 2012 8:02:34 AM UTC-5, Garry Polley wrote:
>
> Here is an example of yet another way to do it 
> http://pastebin.com/JUnk4epK. I like this way because it does not 
> introduce too much extra code into the codebase.   
>
> I'd really like if I could just add an include function called 
> decorated_include and pass the decorator and the urls to include to that 
> function.  It would do the same thing this bit of code is doing. 
>
> On Thursday, September 20, 2012 11:22:01 AM UTC-5, Garry Polley wrote:
>>
>> Currently I am having to choose between two ways to decorate 3rd party 
>> apps views:
>>
>> 1) Use a middleware (
>> http://stackoverflow.com/questions/2164069/best-way-to-make-djangos-login-required-the-default
>> ) 
>>
>> 2) Use some url 'magic' to apply the decorator (
>> http://stackoverflow.com/questions/2307926/is-it-possible-to-decorate-include-in-django-urls-with-login-required
>> )
>>
>> What I would like to do is this:
>>
>> url(r'^authurls', login_required(include('someapp.urls'), 
>> login_url='path/to/login'))
>>
>>
>> So 2 questions:
>>
>> 1)  What does everyone else do to accomplish this?
>>
>> 2) What should 3rd party apps (or Django) do to allow you to decorate 
>> their views, if they should at all? 
>>
>>

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



Re: How often does Django need updates/patches?

2012-09-21 Thread Taylor Smith
thanks very much, that's exactly what we needed to know!
 

On Friday, September 21, 2012 6:39:43 AM UTC-6, Russell Keith-Magee wrote:

> On Fri, Sep 21, 2012 at 10:56 AM, Taylor Smith 
>  
> wrote: 
> > Our new website is being built on Django and we are trying to figure out 
> the 
> > easiest way to host and maintain the site. 
> > It seems there are a few managed hosting options like webfaction and 
> heroku, 
> > but they will only handle the linux and database patches and updates. 
> > 
> > I am hoping to find out how often Django need to be updated. -- like 
> every 
> > month? or more like one or twice a year? 
> > can a non-developer handle these updates or would we be better off 
> hiring 
> > someone? 
>
> At any given time, Django has three supported versions: 
>
>  * The current development trunk, updated on a daily basis. This isn't 
> a packaged version; it's just the current 'tip' of the code 
> repository. 
>
>  * The current Stable release (currently 1.4) 
>
>  * The current Security release (currently 1.3) 
>
> We publish a new stable release roughly every 12 months, at which 
> point the current stable moves to security, and the security release 
> becomes unsupported. So - somewhere around the end of this year, you 
> can expect to see a 1.5 stable release announced, which will make 1.4 
> the security release, and 1.3 will become unsupported. This means that 
> if you write code against the current stable Django release, you've 
> probably got about 2 years before you will need to look at doing a 
> major version upgrade. 
>
> If we are notified of a security problem, we will make a point release 
> for the stable and security versions. These releases are entirely 
> dictated by the reporting of security issues, so there's no formal 
> schedule -- however, historically, there is generally a couple of 
> months between security releases. 
>
> When a security release happens, upgrades are generally pretty simple. 
> The update process is generally not much more complicated than "pip 
> install -u django" (or whatever equivalent is appropriate for your 
> deployment platform). Security releases are announced on the 
> django-announce mailing list, as well as on our blog. 
>
> On larger version updates, there are sometimes some minor changes 
> between versions. However, we're aggressive about backwards 
> compatibility, and phasing in changes slowly, so you'll always have 
> plenty of warning if a change is coming; we document all the changes 
> in our release notes; and 
>  where possible, we raise runtime warnings letting you know of 
> potential problems that may occur in the future as a result of feature 
> changes. 
>
> So - in summary, you're probably looking at no more than a handful of 
> updates a year, and the upgrade process is generally pretty simple. 
> Whether a "non-developer" can handle the updates will really depend on 
> how far "non-developer" they are. The minor release updates shouldn't 
> pose any real difficulty. If you've got someone who is happy to manage 
> a server, they should be able to manage a minor Django update. The 
> major updates (every 1-2 years) will require a little bit more 
> attention to detail. 
>
> Yours 
> Russ Magee %-) 
>

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



Re: url pattern matching

2012-09-21 Thread Brian Patterson
Thanks Larry,
This is what my urls.py file looks like:

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('paperforms.views',
'IS THIS THE LINE I SHOULD MODIFY?
  url(r'^paperforms/$', 'index'),
  url(r'^paperforms/(?P\d+)/$', 'detail'),
  url(r'^paperforms/(?P\d+)/results/$', 'results'),
  url(r'^paperforms/(?P\d+)/vote/$', 'vote'),
)

urlpatterns += patterns('',
url(r'^admin/', include(admin.site.urls)),
)

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



Re: Django Unobtrusive Ajax

2012-09-21 Thread Javier Guerra Giraldez
On Thu, Sep 20, 2012 at 7:12 PM, Russell Keith-Magee
 wrote:
> In the case of Real-time, the answer is maybe. Serving real-time data
> will probably require some modifications to core -- the mechanisms
> used to serve real-time data are different to traditional 'static
> page' mechanisms.

I guess in this context by 'real-time' you mean something
not-exactly-http, like long polling, comet or websockets.

I agree that since plain AJAX is (from the point of view of the
server) just non-necesarily-html but totally http, the Django core
needs no modification, just some clever view handling.

-- 
Javier

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



Re: url pattern matching

2012-09-21 Thread Larry Martell
On Fri, Sep 21, 2012 at 10:27 AM, Brian Patterson  wrote:
> Hi Everyone,
> I'm very new to Django and just trying to explore the basics.  I'm having a
> problem with the url pattern matching.  If i go to site:
> http://mysite:8000/paperforms/
>
> I get the following error:
>
> Using the URLconf defined in mysite.urls, Django tried these URL patterns,
> in this order:
>
> ^admin/
> ^paperforms/ ^paperforms/$
> ^paperforms/ ^paperforms/(?P\d+)/$
> ^paperforms/ ^paperforms/(?P\d+)/results/$
> ^paperforms/ ^paperforms/(?P\d+)/vote/$
> ^paperforms/ ^admin/
>
> The current URL, paperforms/, didn't match any of these.
>
> Shouldn't it find a match on line # 2.

You need an entry that has:

^paperforms/$

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



url pattern matching

2012-09-21 Thread Brian Patterson
Hi Everyone,
I'm very new to Django and just trying to explore the basics.  I'm having a 
problem with the url pattern matching.  If i go to site:
http://mysite:8000/paperforms/

I get the following error:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, 
in this order: 

   1. ^admin/
   2. ^paperforms/ ^paperforms/$
   3. ^paperforms/ ^paperforms/(?P\d+)/$
   4. ^paperforms/ ^paperforms/(?P\d+)/results/$
   5. ^paperforms/ ^paperforms/(?P\d+)/vote/$
   6. ^paperforms/ ^admin/

The current URL, paperforms/, didn't match any of these.

Shouldn't it find a match on line # 2.

thanks for your help.  

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



Re: how to use timezones for datetime fields that are foreign keys in admin interface

2012-09-21 Thread Aymeric Augustin
Le lundi 3 septembre 2012 02:48:24 UTC+2, dalupus a écrit :
>
> On the item list screen however the datetime is not formated and seems 
> to be in utc format like so: 
> 2012-09-03 00:28:21.664176+00:00 
> so it appears it is not adjusting to display the field in the users 
> timezone. 
>
> Any ideas how to get around this? 
>

In Django 1.5, you will be able to use django.utils.timezone.localtime().
https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.timezone.localtime

Unfortunately, there's no such built-in utility in Django 1.4.

-- 
Aymeric.

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



Re: No timezone support for TimeField?

2012-09-21 Thread Aymeric Augustin
Le mardi 31 juillet 2012 22:34:46 UTC+2, Tejinder Singh a écrit :
>
> Django 1.4 does not store aware times for TimeField, it only does for 
> DateTimeField. Its really annoying, as python datetime.time object does 
> support TZINFO just like datetime.datetime objects. I wonder if it is a 
> bug? Btw i have tested it on postgres 9.1 database server


This is a design choice documented here:
https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#naive-and-aware-datetime-objects
(see the last note of this section).

Sorry for answering so late.

-- 
Aymeric.

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



Routing TCPIP requests/ responses to and from a Django app

2012-09-21 Thread Sithembewena Lloyd Dube
Hi everyone,

What is the recommended way to configure a Django project to listen for and
respond to requests via the TCPIP protocol?

I have a project which should listen on a given port, parse the request and
save stuff, then generate a response via the same protocol.

Any ideas? Thanks.

-- 
Regards,
Sithembewena Lloyd Dube

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



Re: Decorate 3rd party app's views

2012-09-21 Thread Garry Polley
Here is an example of yet another way to do it 
http://pastebin.com/JUnk4epK. I like this way because it does not introduce 
too much extra code into the codebase.   

I'd really like if I could just add an include function called 
decorated_include and pass the decorator and the urls to include to that 
function.  It would do the same thing this bit of code is doing. 

On Thursday, September 20, 2012 11:22:01 AM UTC-5, Garry Polley wrote:
>
> Currently I am having to choose between two ways to decorate 3rd party 
> apps views:
>
> 1) Use a middleware (
> http://stackoverflow.com/questions/2164069/best-way-to-make-djangos-login-required-the-default
> ) 
>
> 2) Use some url 'magic' to apply the decorator (
> http://stackoverflow.com/questions/2307926/is-it-possible-to-decorate-include-in-django-urls-with-login-required
> )
>
> What I would like to do is this:
>
> url(r'^authurls', login_required(include('someapp.urls'), 
> login_url='path/to/login'))
>
>
> So 2 questions:
>
> 1)  What does everyone else do to accomplish this?
>
> 2) What should 3rd party apps (or Django) do to allow you to decorate 
> their views, if they should at all? 
>
>

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



Re: How often does Django need updates/patches?

2012-09-21 Thread Russell Keith-Magee
On Fri, Sep 21, 2012 at 10:56 AM, Taylor Smith  wrote:
> Our new website is being built on Django and we are trying to figure out the
> easiest way to host and maintain the site.
> It seems there are a few managed hosting options like webfaction and heroku,
> but they will only handle the linux and database patches and updates.
>
> I am hoping to find out how often Django need to be updated. -- like every
> month? or more like one or twice a year?
> can a non-developer handle these updates or would we be better off hiring
> someone?

At any given time, Django has three supported versions:

 * The current development trunk, updated on a daily basis. This isn't
a packaged version; it's just the current 'tip' of the code
repository.

 * The current Stable release (currently 1.4)

 * The current Security release (currently 1.3)

We publish a new stable release roughly every 12 months, at which
point the current stable moves to security, and the security release
becomes unsupported. So - somewhere around the end of this year, you
can expect to see a 1.5 stable release announced, which will make 1.4
the security release, and 1.3 will become unsupported. This means that
if you write code against the current stable Django release, you've
probably got about 2 years before you will need to look at doing a
major version upgrade.

If we are notified of a security problem, we will make a point release
for the stable and security versions. These releases are entirely
dictated by the reporting of security issues, so there's no formal
schedule -- however, historically, there is generally a couple of
months between security releases.

When a security release happens, upgrades are generally pretty simple.
The update process is generally not much more complicated than "pip
install -u django" (or whatever equivalent is appropriate for your
deployment platform). Security releases are announced on the
django-announce mailing list, as well as on our blog.

On larger version updates, there are sometimes some minor changes
between versions. However, we're aggressive about backwards
compatibility, and phasing in changes slowly, so you'll always have
plenty of warning if a change is coming; we document all the changes
in our release notes; and
 where possible, we raise runtime warnings letting you know of
potential problems that may occur in the future as a result of feature
changes.

So - in summary, you're probably looking at no more than a handful of
updates a year, and the upgrade process is generally pretty simple.
Whether a "non-developer" can handle the updates will really depend on
how far "non-developer" they are. The minor release updates shouldn't
pose any real difficulty. If you've got someone who is happy to manage
a server, they should be able to manage a minor Django update. The
major updates (every 1-2 years) will require a little bit more
attention to detail.

Yours
Russ Magee %-)

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



Re: Setting an unusable password on an existing user

2012-09-21 Thread Andrew Macgregor
AFAIK you can set it to ! in the admin interface. Don't use the change 
password form, just enter ! into the password field on the Auth User table. 
I believe this will cause has_usable_password() to return False.

Cheers, Andrew.

On Friday, September 21, 2012 2:16:22 PM UTC+8, nav wrote:
>
> Hi,
>
> Is there any way to set the password of an existing user to and unusable 
> value like none? 
>
> I tried user.set_unusable_password() and subsequently user.save() but this 
> did not work.
>
> Other than using this method is there a way to set the password to None or 
> such like so that the user.has_usable_password() method will return False 
> instead of True?
>
> Many Thanks,
> nav
>
>

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



How often does Django need updates/patches?

2012-09-21 Thread Taylor Smith
Our new website is being built on Django and we are trying to figure out 
the easiest way to host and maintain the site. 
It seems there are a few managed hosting options like webfaction and 
heroku, but they will only handle the linux and database patches and 
updates. 

I am hoping to find out how often Django need to be updated. -- like every 
month? or more like one or twice a year? 
can a non-developer handle these updates or would we be better off hiring 
someone? 

any advice is much appreciated!

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



mako how to access STATIC_URL (in django)

2012-09-21 Thread mengdexin
In django, template can access  {{ STATIC_URL }} defined in setting.py.

When use Make in django, how to achive it ?

thank u.

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



Re: reduce number of DB-Queries

2012-09-21 Thread Martin J. Laubach

>
> Is this how you meant to set the instance variable or did you mean in 
> another way?
>
> def __init__(self, *args, **kwargs):
> super(Player, self).__init__(*args, **kwargs)
> self.matches = Match.objects.select_related().filter( Q(opp1=self) 
> | Q(opp2=self) )


  Yes, that's what I meant.

mjl
 

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



Re: Setting an unusable password on an existing user

2012-09-21 Thread Nandakumar Chandrasekhar

Thanks Paul,

I have tried this on the Django shell and works for me as well.

Since I am using some third party software to do social site 
authentication I might have made a mistake and not accessed the actual 
django user object.


Thanks once again.

nav

On Friday 21 September 2012 03:17 PM, Paul Backhouse wrote:

Works for me...


from django.contrib.auth.models import User
user = User.objects.latest('id')
user.has_usable_password()

True

user.set_unusable_password()
user.has_usable_password()

False


On Thu, 2012-09-20 at 23:16 -0700, nav wrote:

Hi,

Is there any way to set the password of an existing user to and
unusable value like none?

I tried user.set_unusable_password() and subsequently user.save() but
this did not work.

Other than using this method is there a way to set the password to
None or such like so that the user.has_usable_password() method will
return False instead of True?

Many Thanks,
nav



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





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



Re: Setting an unusable password on an existing user

2012-09-21 Thread Paul Backhouse
Works for me...

>>> from django.contrib.auth.models import User
>>> user = User.objects.latest('id')
>>> user.has_usable_password()
True
>>> user.set_unusable_password()
>>> user.has_usable_password()
False


On Thu, 2012-09-20 at 23:16 -0700, nav wrote:
> Hi,
> 
> Is there any way to set the password of an existing user to and
> unusable value like none? 
> 
> I tried user.set_unusable_password() and subsequently user.save() but
> this did not work.
> 
> Other than using this method is there a way to set the password to
> None or such like so that the user.has_usable_password() method will
> return False instead of True?
> 
> Many Thanks,
> nav
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/yqNmZJR5mJgJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users
> +unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


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



Re: reduce number of DB-Queries

2012-09-21 Thread kloetpatra
Wow thanks!
That's really going fast now.
I would have never come to that idea :)

One more question:
Is this how you meant to set the instance variable or did you mean in 
another way?

def __init__(self, *args, **kwargs):
super(Player, self).__init__(*args, **kwargs)
self.matches = Match.objects.select_related().filter( Q(opp1=self) 
| Q(opp2=self) )

On Friday, September 21, 2012 11:15:34 AM UTC+2, Martin J. Laubach wrote:
>
> My problem is when want to display overall player statistics I get about 
>> 1200 DB-Queries.
>> This is because for each player there will be 5 Queries due to 
>> matches_won, matches_draw, goals, matches_played functions.
>>
>
>   First easy optimisation: keep  Match.objects.select_related().filter( 
> Q(opp1=self)|Q(opp2=self)) in an instance variable and use that QuerySet 
> as base of all your calculations. Do NOT add additional filters for 
> matches_draw/matches_won/matches_played, instead iterate over the results 
> and do the calculations in Python. That way the QuerySet result will be 
> cached the first time you're iterating over it and won't result in any more 
> database accesses later on.
>
>Cheers,
>
> mjl
>
>

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



Re: reduce number of DB-Queries

2012-09-21 Thread Martin J. Laubach

>
> My problem is when want to display overall player statistics I get about 
> 1200 DB-Queries.
> This is because for each player there will be 5 Queries due to 
> matches_won, matches_draw, goals, matches_played functions.
>

  First easy optimisation: keep  Match.objects.select_related().filter( 
Q(opp1=self)|Q(opp2=self)) in an instance variable and use that QuerySet as 
base of all your calculations. Do NOT add additional filters for 
matches_draw/matches_won/matches_played, instead iterate over the results 
and do the calculations in Python. That way the QuerySet result will be 
cached the first time you're iterating over it and won't result in any more 
database accesses later on.

   Cheers,

mjl

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



reduce number of DB-Queries

2012-09-21 Thread kloetpatra
Hi!
I have the following models:

class Player(models.Model):
name = models.CharField('Name', max_length=40)
 
def __unicode__(self):
return self.name
 
def goals(self):
g = 0
ms = Match.objects.select_related().filter( 
Q(opp1=self)|Q(opp2=self) )
for m in ms:
if (m.opp1==self):
g += m.opp1_goals
else:
g += m.opp2_goals
return g

def matches_won(self):
ms = Match.objects.filter( (Q(opp1=self) & 
Q(opp1_goals__gt=F('opp2_goals'))) |
(Q(opp2=self) & Q(opp2_goals__gt=F('opp1_goals'))) ).count()
return ms
 
def matches_draw(self):
ms = Match.objects.filter( (Q(opp1=self) & 
Q(opp1_goals__exact=F('opp2_goals'))) |
(Q(opp2=self) & Q(opp2_goals__exact=F('opp1_goals'))) ).count()
return ms

def match_points(self):
p = 0
p += 3 * self.matches_won()
p += 1 * self.matches_draw()
return p

def matches_played(self):
return Match.objects.filter(Q(opp1=self) | Q(opp2=self)).count()


class Match(models.Model):
class Meta:
verbose_name_plural = "Matches"
opp1 = models.ForeignKey(Player, related_name="player1")
opp2 = models.ForeignKey(Player, related_name="player2")
opp1_goals = models.IntegerField("Goals P1")
opp2_goals = models.IntegerField("Goals P2")
 
def __unicode__(self):
return "%s %d:%d %s"%(self.opp1.name, self.opp1_goals, 
self.opp2_goals, self.opp2.name)

My problem is when want to display overall player statistics I get about 
1200 DB-Queries.
This is because for each player there will be 5 Queries due to matches_won, 
matches_draw, goals, matches_played functions.
How is it possible to retrieve those "calculated properties" without having 
so much queries?

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



Redirects middelware not working as it should

2012-09-21 Thread galgal
I set my redirect, for example from: /testpage/mysite.php  to 
/my-new-django-site/
It won't work if i enter a page mydomain://testpage/mysite.php but works 
on: mydomain://testpage/mysite.php/
"/" trailing slash.

How to make it work?

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



Re: template rendering progress

2012-09-21 Thread Philippe Raoult
Actually I'm already doing something similar. My question was more "how to 
know how far the rendering progress is". Right now I load a template and 
call render() on it but I don't have a way of knowing how much progress is 
made in real time. 

On Friday, September 21, 2012 7:38:27 AM UTC+2, Jani Tiainen wrote:
>
> 19.9.2012 16:13, Philippe Raoult kirjoitti: 
> > Hello all, 
> > 
> > I'm using django templates to generate pdf listings in my app. After 
> > running render() on the template, reportlab is called to create the pdf. 
> > 
> > My issue is that those listings can get quite big (hundreds of pages, 
> > with images) and thus take very long to render. Reportlab has progress 
> > callbacks that allow me to have a nice progress bar on screen, but the 
> > template rendering doesn't seem to offer this functionality. Has anyone 
> > managed to implement this or has any suggestion regarding this topic ? 
> > 
> > Regards, 
> > Philippe 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/django-users/-/kc5IlCznZ1wJ. 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > django-users...@googlegroups.com . 
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en. 
>
> You need to push your rendering task as "external" job. Celery is very 
> good at it and it does integrate with Django very well. 
>
> Basic idea is that you have view that starts the task and returns you 
> the progress view that is either refreshed by using meta-tag or quite 
> common ajax-approach to poll a view that returns progress value. And of 
> course some view to actually fetch the result. 
>
> But there is nothing in template engine that can offer this kind of 
> features since it's property of HTTP protocol and how request/response 
> cycle goes. 
>
> -- 
> Jani Tiainen 
>
> - Well planned is half done and a half done has been sufficient before... 
>

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



Re: Instaling django

2012-09-21 Thread Arman Goshayeshi
Thank you very much, sorry for the delay of my answer


On 31 August 2012 08:14, Jon Blake  wrote:

> What O/S?
>
> I installed Django 1.4.1 today on my Linux F14 box today by:
>
> 1. Downloading Django-1.4.1.tar.gz from
> https://www.djangoproject.com/download/
> 2. As root:
> # tar xzvf Django-1.4.1.tar.gz
> # cd Django-1.4.1
> # python setup.py install
> # exit
> 3. Test it:
> $ python
> >>> import django
> >>> print django.get_version()
> 1.4.1
>
> HTH,
>   Jon
>
>
> On Thursday, August 30, 2012 4:28:40 PM UTC+10, Balle wrote:
>>
>> Hi,  I have been trying to download django with every options but when i
>> run pyhton on the terminal and then asks to import django.  It always says
>> no mudule named django.  Could you pls help, donload it.  Thank you in
>> advance
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Q47WcAEp6vMJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Setting an unusable password on an existing user

2012-09-21 Thread nav
Hi,

Is there any way to set the password of an existing user to and unusable 
value like none? 

I tried user.set_unusable_password() and subsequently user.save() but this 
did not work.

Other than using this method is there a way to set the password to None or 
such like so that the user.has_usable_password() method will return False 
instead of True?

Many Thanks,
nav

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