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

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 > > >

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.

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

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

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

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

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

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

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

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

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

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

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

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:

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

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

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

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

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

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

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')

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

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',

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

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

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

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

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+)/$',

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 >

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: >

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:

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

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?

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. --

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

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

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,

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

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

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,

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,

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

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)

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

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

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

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,

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:

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