what happens to channels consumer instance after disconnect

2020-04-22 Thread BR
What happens to a consumer instance after a websocket client disconnects? 
Is there any specific cleanup of the instance done, or just regular garbage 
collection?

Is it possible to reconnect to a channels consumer instance to recover the 
state of that instance?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1567d416-f2e4-49ee-a4c0-04f71a82cdc1%40googlegroups.com.


Re: Open Source IDE to start with Django Web development

2019-11-07 Thread BR
Something to consider is that Django is Python, HTML, and Javascript. VS 
Code can do all three with highlighting, formatting, etc, and it all 
happens automatically as you switch between editing files. The Git support 
is excellent as well, as others said.

On Thursday, November 7, 2019 at 9:18:25 AM UTC-5, johnf wrote:
>
> Every time I see one these which is the best IDE - I never see WingIDE.  I 
> often wonder why.  It works as well as any other of the suggestions?
>
> Johnf
>
> On 11/7/19 5:38 AM, Siratim Mustaquim wrote:
>
> Why don't you just try a few IDE's and text editors, IDK how much OSS or 
> NonOSS IDE will affect your project, but if 'you' don't feel comfortable 
> with it, I can guarantee, that will affect your project. 
>
> Assuming u are not in a limited internet connection package, download a 
> few of the available ones, and start using them.
>
> PyCharm IDE is a great tool. But it may feel big and bulky sometimes, 
> while VSCode editor is faster in terms of opening projects.
>
> I tried Geanny, didn't like it, because it made some weird behavior I 
> terms of indentation and tabs, I couldn't figure how I could make 
> "tab=4spaces" instead of "tab=1tab".
>
> Vim and Vim like ones are too difficult for me, so I skipped. 
>
> I saw people developing python in Visual Studio. Again, amazing IDE, might 
> feel a bit heavy at one point.
>
> And last but not least, The one and Only IDLE. 
> I still like it, and for quick scripting and quick checks, amazing. 
>
> So, pick one that is comfortable for you. What is easy to me might not be 
> the same for u. Try a few, find what u like.
>
> Happy Coding
>
> On Thu, Nov 7, 2019, 7:03 PM vineet daniel  > wrote:
>
>> VSCode.
>>
>> On Thu, 7 Nov 2019, 16:39 John McClain, > > wrote:
>>
>>> agreed, but... 
>>>
>>> pycharm is dedicated to python and vs code is generally suitable for any 
>>> others assuming the person operating can configure their environments.
>>>
>>> the person was asking for an IDE suitable for python specifically which 
>>> is why I throughout pycharm
>>>
>>> ultimately, I would go with vs code but it takes a bit more knowledge 
>>> than pycharm does
>>>
>>> On Thu, 7 Nov 2019 at 11:00, Parth Joshi >> > wrote:
>>>
 VS Code works like a Charm. (Pun intended :-) ) 

 There are lint, autocomplete and git extensions which you can use for 
 setting up dev environment.

 Regards, 

 Parth Joshi



 On 06-Nov-2019, at 4:22 PM, himanshu goyal >>> > wrote:

 To Community, 

 Greetings!

 Could you suggest a good open source IDE for Django? URL to download 
 will be helpful.

 Thanks,
 Himanshu
 India

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django...@googlegroups.com .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/767f5e59-20b7-4a3a-989a-dedb0e40ceff%40googlegroups.com
  
 
 .


 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django...@googlegroups.com .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/37EB9045-4C0B-465E-BDF8-C90A73956A45%40gmail.com
  
 
 .

>>>
>>>
>>> -- 
>>> John McClain
>>>
>>> Cell: 085-1977-823
>>> Skype: jmcclain0129
>>> Email: jmccla...@gmail.com 
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAN-hv_oUtRDmx0y6i1oRZvHTXK-qgiUF%2Bq5r5VJMDrCTjja7Ow%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAJPbAW-AN%2BMp4g0%2BNX4nYzfin6dSzxySNLVgn_RXp7NOG7RRsg%40mail.gmail.com
>>  
>> 

Re: mariadb/mysql database (2006, 'MySQL server has gone away')

2019-11-07 Thread BR
I'm still having this issue, and it definitely seems Channels related. When 
the issue occurs, I can logout/login and do other things on the Django only 
portion of the site. As soon as I try to make DB requests from within a 
Channels consumer, the error pops up. Restarting the Daphne server resolves 
the issue.

On Friday, November 1, 2019 at 9:13:41 AM UTC-4, BR wrote:
>
> I think I'm experiencing an issue related to:
>
> https://github.com/django/channels/issues/1234
>
> where I get (2006, 'MySQL server has gone away') after trying to establish 
> a new channels connection with calls using database_sync_to_async(). I have 
> set my Django DB CONN_MAX_AGE to 300 (5 minutes) and my MariaDB 
> wait_timeout to 28800 (was 600 originally). All this did was extend the 
> time before I saw the issue.
>
> Why would Django not be clearing out old connections, and why doesn't it 
> just open a new one?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/acd7afb1-0ee2-4259-8392-8f0a6cc9f34a%40googlegroups.com.


mariadb/mysql database (2006, 'MySQL server has gone away')

2019-11-01 Thread BR
I think I'm experiencing an issue related to:

https://github.com/django/channels/issues/1234

where I get (2006, 'MySQL server has gone away') after trying to establish 
a new channels connection with calls using database_sync_to_async(). I have 
set my Django DB CONN_MAX_AGE to 300 (5 minutes) and my MariaDB 
wait_timeout to 28800 (was 600 originally). All this did was extend the 
time before I saw the issue.

Why would Django not be clearing out old connections, and why doesn't it 
just open a new one?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9c03f6d4-4816-4455-bf8f-d71839d8aa96%40googlegroups.com.


Re: Django Channels persistent DB connection

2019-10-30 Thread BR
I should add: My interest would be to have a DB connection that lasts the 
lifetime of the parent consumer. Does it already do this, and am I 
imagining things?

On Wednesday, October 30, 2019 at 12:17:54 PM UTC-4, BR wrote:
>
> I moved from a local sqlite3 DB file to a shared remote (local LAN) 
> MariaDB server and noticed a bit of a slow down. On top of the DB now being 
> remote, I'm also using SSL to encrypt the DB information. Based on the 
> description of *database_sync_to_async* it sounds like the connection is 
> closed/cleaned up on each call.
>
> Is there an option for a persistent DB connection in Channels?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bcacfbad-e250-4133-be15-4de78a3fe555%40googlegroups.com.


Django Channels persistent DB connection

2019-10-30 Thread BR
I moved from a local sqlite3 DB file to a shared remote (local LAN) MariaDB 
server and noticed a bit of a slow down. On top of the DB now being remote, 
I'm also using SSL to encrypt the DB information. Based on the description 
of *database_sync_to_async* it sounds like the connection is closed/cleaned 
up on each call.

Is there an option for a persistent DB connection in Channels?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/713d292b-def8-4339-a277-f356ba7f23fc%40googlegroups.com.


Re: Daphne with absolute path to ASGI file

2019-10-22 Thread BR
This is Windows by the way

On Tuesday, October 22, 2019 at 3:56:47 PM UTC-4, BR wrote:
>
> I've been using Daphne for months without issue, and have reorganized my 
> project structure to make things a bit easier. However, it appears that 
> Daphne needs to be run from the folder containing the Django project module 
> like so:
>
> daphne project.asgi:application
>
> How can I specify the full path to project.asgi:application?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7c81be7-f918-494b-b0d0-406d5e1805cf%40googlegroups.com.


Daphne with absolute path to ASGI file

2019-10-22 Thread BR
I've been using Daphne for months without issue, and have reorganized my 
project structure to make things a bit easier. However, it appears that 
Daphne needs to be run from the folder containing the Django project module 
like so:

daphne project.asgi:application

How can I specify the full path to project.asgi:application?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4fbd3a46-3939-492a-a893-86d96fbe21f5%40googlegroups.com.


Re: Channels 2 using asyncio run_in_executor

2019-10-18 Thread BR
>From your experience, can you provide a brief overview of the types of 
calls that would cause a deadlock?

Maybe that's what I was experiencing earlier, but after spending today on a 
work around, I can't replicate my original problem. Both sync_to_async and 
run_in_executor work just fine right now.

On Friday, October 18, 2019 at 2:37:25 PM UTC-4, Andrew Godwin wrote:
>
> It should be fine, but you will need to be careful - there's a lot of 
> side-effects with run_in_executor you should be aware of like the way 
> exceptions propagate (Django won't handle them right for you) and the 
> possibility of deadlock.
>
> Andrew
>
> On Fri, Oct 18, 2019 at 11:27 AM BR > 
> wrote:
>
>> Should I expect any issues using asyncio run_in_executor to run blocking 
>> code? I realize there is the sync_to_async function as well, but that 
>> wasn't working in my case. I'm using multiprocessing.Queue to share data 
>> with a new process, and when I try to use queue.get() with either 
>> sync_to_async or run_in_executor, the calling method hangs.
>>
>> My solution for now was to run a queue.get() listener in a separate 
>> thread, but it would have been nicer to use await with run_in_executor. Is 
>> there any custom configuration of the consumer event loop that prevents 
>> some times of functions from running, even when run with appropriate 
>> wrapping functions?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d4ce7dc-2000-41e6-9de8-280769c92ddb%40googlegroups.com.


Channels 2 using asyncio run_in_executor

2019-10-18 Thread BR
Should I expect any issues using asyncio run_in_executor to run blocking 
code? I realize there is the sync_to_async function as well, but that 
wasn't working in my case. I'm using multiprocessing.Queue to share data 
with a new process, and when I try to use queue.get() with either 
sync_to_async or run_in_executor, the calling method hangs.

My solution for now was to run a queue.get() listener in a separate thread, 
but it would have been nicer to use await with run_in_executor. Is there 
any custom configuration of the consumer event loop that prevents some 
times of functions from running, even when run with appropriate wrapping 
functions?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com.


Daphne/Twisted exception when serving SSL/TLS

2019-05-03 Thread BR
I get the following traceback shortly after running Daphne with TLS enabled 
(it doesn't occur when TLS is not configured). Any ideas? It doesn't seem 
to affect anything, but I thought I would bring it up here before trying to 
submit an issue:

2019-05-03 12:41:45,252 ERRORException in callback 
AsyncioSelectorReactor.callLater..run() at 
c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\internet\asyncioreactor.py:287
handle: .run() at 
c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\internet\asyncioreactor.py:287>
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
  File 
"c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\internet\asyncioreactor.py",
 
line 290, in run
f(*args, **kwargs)
  File 
"c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\web\http.py",
 
line 2339, in forceAbortClient
self.transport.abortConnection()
  File 
"c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\protocols\tls.py",
 
line 435, in abortConnection
self._shutdownTLS()
  File 
"c:\users\user\virtualenvs\channels_test\lib\site-packages\twisted\protocols\tls.py",
 
line 338, in _shutdownTLS
shutdownSuccess = self._tlsConnection.shutdown()
AttributeError: 'NoneType' object has no attribute 'shutdown'

This is on Windows 10, but I saw it on my Ubuntu server as well (again, 
when TLS is enabled).

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


Daphne error log

2019-05-03 Thread BR
Is there an error log for the project Daphne is serving? I see the access 
log is on the console, but only errors from Daphne itself seem to output 
here.

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


Re: Run Daphne as non-root on low ports

2019-05-02 Thread BR
Thanks for the feedback. I guess I was thinking that since Daphne is the 
"reference server" for ASGI, that it would have features available for 
production type use. I only came across WebSocket stuff yesterday so this 
is all quite new. I suppose my remaining issue is that SSL certificates 
seem to only (usually) accessible by root, so in any situation it seems 
that Daphne can only terminate SSL when running in root, unless permissions 
on the private key are changed.

I'm looking into the nginx reverse proxy with SSL termination at the moment.

On Thursday, May 2, 2019 at 9:49:41 AM UTC-4, Andrew Godwin wrote:
>
> Daphne does not have uid-changing built in, no - it's too simplistic for 
> that, unfortunately.
>
> It's worth noting that systemd has this ability built in - it will listen 
> on sockets for you and bind the socket to an application as needed. 
> Otherwise, as the other poster noted, you can also use a reverse proxy to 
> terminate SSL, which is what Daphne is built assuming (the SSL support in 
> there is because it comes for free with Twisted, rather than being 
> specifically added).
>
> Andrew
>

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


Run Daphne as non-root on low ports

2019-05-02 Thread BR
I'm running a simple Django/Channels website using Daphne. Traffic will be 
relatively low and will likely only see 1-2 clients at a time. I figured 
this would be a good use case for Daphne to serve both HTTPS and WebSockets.

Does Daphne have a mechanism for starting as root and dropping down to a 
non-root user after it is running? Root is required at startup because I 
want it to bind to port 80 or 443, and it needs to access the SSL 
certificate.

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


Anyone using a javascript MVC on top of Django?

2012-04-17 Thread br
We have an extremely javascript & ajax heavy application.  To put it
one way, we have blatently disregarded graceful degradation in order
to build the type of application we want to build.  We're finding that
as the thing grows, the interactions between the front end javascript
and django are becoming more and more painful, mostly due to the
contortion we have to put django through to make it work with our
design philosophy.   (examples: tons of dynamic list filtering,
tagging, object cloning, saving state across multi-page forms, etc.).
This isn't a post to criticize Django, I love it.  Nor am I inviting a
critique of the way we build software.  I'm just looking for a way to
make Django work better for us and am considering switching to a model
where we use a javascript MVC on top of Django, with JSON bridging the
in-between.  We probably should have gone that route to begin with.
Has anyone had good success with any of them?  Backbone.js seems to be
the most popular.  Although, based on this:
http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/
I may check out ember.js.

Thanks,

Ben

-- 
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: IE9+Django,Don't respond or Socket error!!!

2012-03-27 Thread br
This is a problem of django development server, running on windows,
and IE(7-9). Basically, the server locks up, and it doesn't really
give much as far as useful errors go.

Apparently no one that contributes to django uses IE for development
and has been able to replicate this issue, because the issue has been
closed as "works for me".  https://code.djangoproject.com/ticket/15178
.

This bug was a huge problem for our windows developers, and took a few
days to figure out.  It happened after we'd been developing for a
while, and I'm not sure what it was about our particular project that
makes it fail.  This is only a problem with runserver , and will not
effect your production server.

Here are work-arounds:

1) install and use another web server for development
- I recommend either django-extension's runserver_plus , or gunicorn
(for either, just install the package, add to installed_apps, and then
run either "manage.py runserver_plus" or "manage.py run_gunicorn"
just like you would runserver).docs: 
https://github.com/django-extensions/django-extensions
or http://gunicorn.org/run.html#contents

2) If you want to use the runserver that comes with django:
- to run runserver, use "manage.py runserver 0.0.0.0:8000" instead of
the default (which goes to localhost or 127.0.0.1) , and then figure
out your computer's IP address in your intranet (ivarious ways to do
this, i use "ipconfig" from command line and pick the one that
probably starts with 192.168).  Then when you want to access your app,
do it at http://:8000


Good luck, hope that solves it

Ben

PS Django extensions has other good stuff too. I love shell_plus, the
model graphing, and the profile server .









On Mar 25, 1:19 am, Aommonly  wrote:
> ===
>
> Exception happened during processing of request from ('127.0.0.1',
> 60076)
> Traceback (most recent call last):
>   File "C:\Python27\Lib\SocketServer.py", line 284, in
> _handle_request_noblock
>     self.process_request(request, client_address)
>   File "C:\Python27\Lib\SocketServer.py", line 310, in process_request
>     self.finish_request(request, client_address)
>   File "C:\Python27\Lib\SocketServer.py", line 323, in finish_request
>     self.RequestHandlerClass(request, client_address, self)
>   File "E:\workspace\Police\lib\site-packages\django\core\servers
> \basehttp.py",
> line 560, in __init__
>     BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
>   File "C:\Python27\Lib\SocketServer.py", line 639, in __init__
>     self.handle()
>   File "E:\workspace\Police\lib\site-packages\django\core\servers
> \basehttp.py",
> line 600, in handle
>     self.raw_requestline = self.rfile.readline()
>   File "C:\Python27\Lib\socket.py", line 447, in readline
>     data = self._sock.recv(self._rbufsize)
> error: [Errno 10054]
>
> 
>
> what can I  do

-- 
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 view and add related objects on both sides of an m2m field in admin

2011-08-18 Thread br
It seems that by definition, an M2M field is basically symettrical, at
least underneath.  However,  I'm having trouble figuring out how to
access and set M2M fields in the Django Admin via the Model that
doesn't declare the M2M.

Here is the example I've been working with to try to figure it out:

class Movie(models.Model):
name = models.CharField(max_length=50)

class Actor(models.Model):
name = models.CharField(max_length=50)
movie_set = models.ManyToManyField(Movie)

admin.site.register(Movie)
admin.site.register(Actor)


I can set the Movies for the Actor, but I'd like to be able to do
both: set Movies for Actor, or set Actors for Movie.  Is this readily
doable in Django Admin?  I tried using an Inline, but it wanted a
ForeignKey not an M2M.

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



Recommendations for load testing/profiling a django site server?

2011-07-21 Thread br
I am running on a Linode 768 VPS and may have some stuff going live
before too long.  I'm wondering what the best way to guage whether I
have enough bandwidth/CPU/memory to handle a significant amount of
traffic is and/or to get an idea of the types of loads the site can
handle before i need to upgrade.

Thanks,
Ben


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



Proper way to strip whitespace from Charfields in a form in current version of Django?

2011-07-18 Thread br
There seems to be a raging and unresolved discussion about how to
address the issue of stripping whitespace from form fields in future
versions of Django over on the Developers group:
http://groups.google.com/group/django-developers/browse_thread/thread/90352cc0da78390b
.

In the present, what is the proper place to strip whitespace?

I've starting down this path:

http://www.peterbe.com/plog/automatically-strip-whitespace-in-django-forms

by setting up a BaseModelForm class, but i don't necessarily like the
fact that I could have a field with "blank=False" that will still
validate if you have an input of just whitespace, since apparently
"clean" gets called after validation takes place.  Is the override of
full_clean referenced in the comments the way around this then? Seems
pretty hacky.

Thanks

Ben

-- 
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: Django - can't open image in model save()

2011-07-18 Thread br
Not sure if this is your problem but there are some issues with some
PIL installations and JPG files that require some potential
configuration/install-time magic, so make sure you test on PNG's or
GIF's first and make sure its working with those.  If it ends up being
JPG-specific issue, and google doesn't turn up the work-through for
it, post here, and I can dig up the blog posts I used to resolve my
JPG issues with PIL and Django's ImageField.

Ben

On Jul 18, 7:23 am, Malcolm Box  wrote:
> On 18 July 2011 02:04, galgal  wrote:
>
>
>
>
>
>
>
>
>
> > def upload_path_handler(instance, filename):
>
> > return filename
>
> > class SpectacleGallery(models.Model):
>
> >  image = models.ImageField(upload_to=upload_path_handler)
>
> > def save(self, *args, **kwargs):
>
> >  Image.open(self.image)
>
> >  super(SpectacleGallery, self).save(*args, **kwargs)
>
> >  When I try to open it I get:
>
> > IOError at /admin/index/spectacle/1/
> > cannot identify image file
>
> You should be able to pass SpectacleGallery.image to PIL open - I've done
> similar things in the path.
>
> What happens when you step through the code - what's the value of
> self.image? Is it really a valid image file? Is it where it thinks it is?
>
> Malcolm

-- 
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2011-07-18 Thread br
While this doesn't contribute an answer to your question, I must say
that name "class-based generic views" is a bit misleading . . .
implying that these class-based views are for doing things you want to
do that follow a strictly set pattern out of the box (i.e, listviews,
detailviews, create views, etc.), but that you'll have to use
something else (i.e., function based views) if you are defining your
own views.  However, this is not the case at all.  We wanted to switch
all our views to class-based, and have had great success with writing
our own class-based views by extending built-in view and mixin
classes.  Basically, most of our own views extend the generic
TemplateView and we add in our own Mixins or add functionality to the
overridden class methods. Some of our views extend other generic view
classes. As the documentation gets updated and edited, this paradigm
probably ought to be explained, because for a while I just figured
that i still had to still use function views if I wanted to do
anything custom, beyond what the generic views provide in and of
themselves.  They're a different beast but can be much more DRY and
add some OO awesomeness to your code once you get your head around
them.  For now, I'd recommend looking at the source code to see which
functions you can override, its pretty straightforward.

Ben

On Jul 16, 12:26 pm, Paul Walsh  wrote:
> Hi Russ,
>
> Wow - your response is *exactly* what I needed - thanks a great deal :)
>
> As you mention in there, *because* CreateView gets me so far without the
> Form class (it builds me a form based on the model I declare), I was exactly
> looking to do other "ModelForm" stuff at the CreateView level.
>
> Now it is clear to me what I need to do. Thanks for your class-based generic
> views contribution, and I really hope someone will have the chance to do
> more docs and examples for class-based views.

-- 
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 automatically add a url param to url tags (it is used ubiquitously throughout application)?

2011-07-09 Thread br
FYI i ended up basically created a custom {% url %} tag, which is a
wrapper for the django standard url tag, but which adds the org_slug
as a parameter.  Its a bit hacky/magical but saved me a bunch of
time.  If any one runs into this issue, email me and I can show you
what I did.

On Jul 8, 4:38 pm, br <robert...@gmail.com> wrote:
>  Here's a snippet from my base urls.py:
>
>     (r'^(?P[\w-]+)/manager/mobile/',
>         include('mobilepolls.manager.urls')),
>     (r'^(?P[\w-]+)/manager/display/',
>         include('screens.manager.urls')),
>     (r'^(?P[\w-]+)/display/', include ('screens.urls')),
>
> Each of those apps then defines its own urls.py with various different
> url patterns.
>
> My problem is that I'm having to repeat the following:
>           {% url . . .  org_slug=organization.slug %}
>
> nearly everywhere I ever use a url tag in a template (probably 50x or
> more), because the org_slug is ubiquitous in almost all urls, but is
> always just retreived from the current user's organization. Doesn't
> seem very DRY and is a bit error-prone.  Is there anyway to automate
> this with a custom tag or middleware or something so that i can just
> assume that "org_slug=organization.slug" part of each url tag or add
> it if there is a org_slug regex param in the url?
>
> Background: We recently added organizations in our application to
> provide a single-DB multi-tenancy of sorts.  A user's organization is
> reflected in most of the URL's he/she navigates to.  As a shortcut to
> not always have to access the organization via the
> user.get_profile().organization, I add the current organization (which
> is just a lazy functional reference to a user profile object's
> organization property) to the request via middleware and to each
> request context via a context processor .
>
> Thanks,
>
> Ben

-- 
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 automatically add a url param to url tags (it is used ubiquitously throughout application)?

2011-07-08 Thread br
 Here's a snippet from my base urls.py:

(r'^(?P[\w-]+)/manager/mobile/',
include('mobilepolls.manager.urls')),
(r'^(?P[\w-]+)/manager/display/',
include('screens.manager.urls')),
(r'^(?P[\w-]+)/display/', include ('screens.urls')),

Each of those apps then defines its own urls.py with various different
url patterns.

My problem is that I'm having to repeat the following:
  {% url . . .  org_slug=organization.slug %}

nearly everywhere I ever use a url tag in a template (probably 50x or
more), because the org_slug is ubiquitous in almost all urls, but is
always just retreived from the current user's organization. Doesn't
seem very DRY and is a bit error-prone.  Is there anyway to automate
this with a custom tag or middleware or something so that i can just
assume that "org_slug=organization.slug" part of each url tag or add
it if there is a org_slug regex param in the url?


Background: We recently added organizations in our application to
provide a single-DB multi-tenancy of sorts.  A user's organization is
reflected in most of the URL's he/she navigates to.  As a shortcut to
not always have to access the organization via the
user.get_profile().organization, I add the current organization (which
is just a lazy functional reference to a user profile object's
organization property) to the request via middleware and to each
request context via a context processor .

Thanks,

Ben

-- 
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: anybody using PhoneGap with Django

2011-07-08 Thread br
I am currently in the middle of a project where we are planning on
using Django with PhoneGap . . . Haven't completed yet, or gotten to
the PhoneGap part of it, so can't report its success or not yet.

Basically, we are using jQuery Mobile to develop a complete mobile
application that operates on a pair of cached JSON objects, one to
define the page flow of the application and the page contents, and the
other to store form results to be returned to the server or stored in
localstorage.  I am not using Django templates for anything, but
rather just going to use TastyPie to provide a REST interface for the
app's models in order to provide and receive the JSON objects to and
from the front end. So essentially- just using Django for the back
end. We also looked at Sencha touch vs. jQMobile for the front end but
went with jQ Mobile because my front end developer was much more
comfortable with it and was already familiar with jQuery.  Once we get
the thing working as an addressable mobile web app, we intend to
package and wrap it as a PhoneGap app.   I can post an update on our
success or failures in a month or so when the project has come
together more.  As of now, just he front end is completed to operate
on the JSON objects and I am working on the models and REST interface
for it.

Ben

On Jul 8, 8:01 am, Brian Bouterse  wrote:
> I would be interested to hear this as well...
>
>
>
>
>
>
>
>
>
> On Fri, Jul 8, 2011 at 12:44 AM, John Fabiani  wrote:
> > On Thursday, July 07, 2011 08:48:51 pm Andy McKay wrote:
> > > On 2011-07-07, at 2:22 PM, John Fabiani wrote:
> > > > I'm wondering if anyone has had any success with PhoneGap and Django?
>
> > > Yes.
> > > --
> > >   Andy McKay
> > >   a...@clearwind.ca
> > >   twitter: @andymckay
>
> > LOL - I guess I could have asked a better question.  Can I assume you have
> > had
> > success with Django and PhoneGap?  If so would you take the time to explain
> > in
> > a general your experience with PhoneGap.  I have been told that the
> > combination is very slow - although I don't see any reason that it would
> > be.
> > I was also told that debugging was very difficult.
>
> > Johnf
>
> > --
> > 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.
>
> --
> Brian Bouterse
> ITng Services

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



Multiple Inheritence of Abstract Base Model Classes, or plain Mixins?

2011-06-22 Thread br
I asked a similar question a few days ago but got no response.  Since
then, I've poked around SO and come up with a few potential ways to do
it, but wonder if there is a *correct* Django way to do it or if there
are hidden problems lurking behind one of them.

Basically I have a few different base concepts for models and would
like to mix and match them . . . Organizational, Taggable, and
TimeStamped .

I've been using Abstract base models for each, but wonder if Mixins
(where there is no inner "Meta" class with abstract=True, and does not
extend from models.Model) is better for some reason than having each
be an abstract base model and using multiple inheritance for each
child class that needs these properties.  Mixins were suggested to me
on SO, but it seems that Abstract models were created just for this
sort of thing . . . just haven't seen them used with multiple
inheritance.

Anyone have any guidance here, or is it 6 cents one way half a dozen
the other. . .

Ben

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



Is multiple inheritance with abstract model classes ok?

2011-06-20 Thread br
If I have three different abstract model base classes . . . I'd like
to use them in multiple inheritance, sort of like Mixins.  Any
problems with this?

E.g.,

class TaggableBase(models.Model):

. . .

class Meta:
abstract = True

class TimeStampedBase(models.Model):

. . .

class Meta:
abstract = True

class OrganizationalBase(models.Model):

. . .

class Meta:
abstract = True

class MyTimeStampedTaggableOrganizationalModel(OrganizationalBase,
TimeStampedBase, TaggableBase):

. . .



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



Proper way to reuse django's built-in admin javascript in my own templates (outside admin)?

2011-06-17 Thread br
Hi,

I am using inline fromsets in my own custom forms and would like to
reuse the same functionality that is provided django admin's
inlines.js, particularly the add row button functionality, in order to
add rows to my own inline formsets, similarly as is done in django's
admin.  What is the proper way to reference these files?

Should I copy the files into my own static directory, or should i just
include {{STATIC_URL}}/admin/js/inlines.min.js in my template.  Or
something else?

Seems like i've seen it recommended either way.  is either way the
correct way of doing it?

Ben

-- 
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 implement multi-tenant, single DB, single site?

2011-06-06 Thread br
Thanks, this is very helpful and gives me some good ideas to start
implementing.

One question I have is:

If i'm using Django's built-in User class (and corresponding
authentication) and I want to be able to associate each user with an
organization and be able to access a user's organization from the view
via the request, what is the best/easiest way to do that?

Ben

On Jun 4, 11:42 pm, Doug Ballance  wrote:
> For our setup we created a separate user,site framework since we do a
> form of vhosting that serves multiple sites from one instance. We have
> a Site model that serves as the root tying all of our other models
> together.  No abstract models or anything fancy, just a FK in each
> model class pointing back to the Site model.  You only have one site,
> but the concept could be the same.. instead of setting the site
> instance for a request in middleware from ip/header info like we do,
> you'd infer and organization instance from the logged on user.
>
> For the view management I'd suggest looking at the class based views,
> and creating a 'tenant aware' base class view that you can sublcass
> for your individual views.  I used the generic class based views as a
> guide for making my own.  I'd suggest starting by looking at the
> source in django.views.generic.list and django.views.generic.detail.
> The get_queryset()/get_object methods are the main points of
> interest.  If you have a middlware set the user (or use django's user
> model) object on the request, you can alter your get_queryset() method
> to restrict the query to only objects the user (or that users
> organization) is allowed since the request will be available on the
> class as self.request.
>
> For my use, I have a similar base class with an altered dispatch()
> method that wraps the base dispatch method in a try/except looking for
> an AuthError exception.  In my view subclasses I override
> get_queryset() to limit queryset per request (to the site/user), and
> do additional permissions checking in get_context_data() raising an
> AuthError exception if there is a permission error.  The altered
> dispatch is responsible for returning an error page or redirecting to
> a login if AuthError is raised at any point in the view process.

-- 
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: Preview for the new website..

2011-06-06 Thread br
My team has a designer (designs stuff in Photoshop), a front-end
developer who is comfortable taking designer's photoshop and
converting it to HTML/CSS/Javascript (and does a bit with django
templates), and then the back-end team (myself and co.) who put the
django behind it.   We are a very design-driven company, and that
complicates my life a bit to put the django behind it (particularly
working with forms, where the front end guys have a lot of fancy
controls and ajaxy page flows, etc., which are not uncomplicated to
implement on the backend), but the sites end up looking cool and
(eventually) working nicely and in a very user-friendly way.

But I would guess not all startup companies, and particularly web
developers who aren't working for a company, have these competencies,
in which case you may look to buy or find public domain html templates
and tweak them and put the code behind them as the previous poster
suggests.

Also, Sencha (Ext JS) is a framework that seems to be geared toward
companies/people where web developers and computer scientists who are
more comfortable with object oriented programming than html and css
have to carry the burden of making a nice front-end for their site,
since the framework manages and dynamically creates a lot of the HTML
and CSS for you and allows you to write stuff in an object-oriented
framework built on javascript.  We looked at sencha but our front-end/
HTML guy hated it so we are sticking with Jquery even though I would
probably go with sencha if i wanted a very ajaxy site but didn't have
him around to tweak all the html/css stuff.  Not sure if/how sencha
plays nicely with Django forms -- in my mind there may be some
challenges there, given the two design philosophies, where sencha
renders your forms automatically for you based on your object
definitions.

Ben
n Jun 5, 12:52 am, raj  wrote:
> I'm a very beginner developer. I'm just wondering how you got the
> actual styling together? Did you bang all that out with photoshop/css/
> javascript or something? Cause I want to make a website, but I don't
> know if I should go ahead and learn this way, or if there is an easier
> way. Thank you.
> -Raj
>

-- 
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 implement multi-tenant, single DB, single site?

2011-06-04 Thread br
I have been scouring the group and interwebs and it seems multi-tenant
comes up quite frequently in various scenarios, and mine is probably a
common one.  However, I haven't been able to distill a Djangooey best-
practice from what i've read, so I figure it won't hurt to bring it up
again.

Here is my situation:

1 site, 1 DB, multiple organizations, each with multiple users, 1
login page and set of client pages.  Not concerned about admin
implementation too much, since we are keeping that to system admins
(us) only.  Also, seems like the Sites framework won't be much help in
my scenario, unless i'm misunderstanding it.

So far, I have created a Organization model, with (automatic) id,
name, slug, and timezone fields,  and a "BaseOrganizationalModel"
Abstract model with a foreign key to an Organization, which i can
extend in any models that need to pertain to an organization.   Seemed
like the way to get started; correct me if I'm wrong. :)

The part I'm getting hung up on is how to manage this in the views and
to associate a user, and each request, with an organization, so that,
in a simple example, if i am in a view that returns a context
containing a list of objects of a model that extends
BaseOrganizationalModel, that I get only the objects that pertain to
the organization of the logged-in user.

Should I write a decorator? Some Middleware? A custom Manager?   (none
of which i've done before, but I'm happy to jump in)

A push in the right direction would be helpful and also pointers to
any apps, code snippets, or discussion that help with implementation
of this type of framework .

Thanks!

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



Example uses of Celery

2011-05-23 Thread br
I understand a lot of production systems use celery and/or cron to
automate task queues and/or scheduling.  I am just getting involved in
a startup and will be the go-to guy for tech stuff and am interested
in what types of tasks people use Celery (or a celery-like platform)
for so that when similar types of things come up in my company, I'll
think of it first.I've read through the manuals a bit, but its
mostly technical and implementations.  I'd like some examples to
analogize to and then I can apply the code  when stuff comes up.I
realize Celery isn't a django-specific tool, but it seems to go hand
and hand a lot of times and we are building our platform in django.

Thanks,

br

-- 
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 manage creation of many-to-one (child) objects on separate page during creation of object

2011-05-16 Thread br
Cool. I'll have to look at that.  Does this support nonlinear form
flows (i.e., you go from Form1 to Form2 back to Form1 and then hit
submit) or is there another app for that?


On May 16, 7:50 am, Lucian Nicolescu <lucia...@gmail.com> wrote:
> Did you check out the form wizard that Django comes 
> with?http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
> Sounds like this is what you are looking for ... multipage forms.
>
> Lucian
>
>
>
>
>
>
>
> On Mon, May 16, 2011 at 4:46 PM, br <robert...@gmail.com> wrote:
> > I have not written this yet, so am not posting code (yet).  Also, I am
> > implementing a client facing interface (not using django admin for
> > this part).
>
> > I am sure this is common thing to do, in fact, I beleive it is done in
> > django admin, but I am somewhat confused as to the best or standard
> > way to do it.  Here is the scenario.
>
> > I am creating a page for editing and/or creating an object. (we'll
> > call it a poll, to be consistent with tutorial.)
> > The page provides a place for user to enter or edit the fields for the
> > poll corresponding to the model fields.
> > The Poll model has another model with a foreign key to it. (e.g.
> > Choice)
> > On the poll page, I want to show a list of the choices for the poll,
> > where each choice has a link to edit the choice, and there is also a
> > link to add a new choice. (for a new poll, there wouldn't be any
> > choices to start)
> > The link takes you to a choice page (or pops out a window page) where
> > you can edit or create the choice.
> > You hit OK on the choice page to come back to the poll page, which has
> > a list of choices that is updated with the new choice or the edited
> > choice.
> > You don't want to save the choice to the database until the poll is
> > saved (i.e. they can hit cancel and the poll and any changes to
> > choices are not saved.)
>
> > How to accomplish this "transaction" back and forth between the two
> > pages, where neither poll nor choices is saved until the Save button
> > is hit on the Poll page?  Specifically, how to pass the data between
> > the two pages without explicitly saving each choice to the DB?  Seems
> > like there is probably a standard mechanism for doing this.
>
> > Thanks,
>
> > Ben
>
> > --
> > 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 
> > athttp://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.



how to manage creation of many-to-one (child) objects on separate page during creation of object

2011-05-16 Thread br
I have not written this yet, so am not posting code (yet).  Also, I am
implementing a client facing interface (not using django admin for
this part).

I am sure this is common thing to do, in fact, I beleive it is done in
django admin, but I am somewhat confused as to the best or standard
way to do it.  Here is the scenario.

I am creating a page for editing and/or creating an object. (we'll
call it a poll, to be consistent with tutorial.)
The page provides a place for user to enter or edit the fields for the
poll corresponding to the model fields.
The Poll model has another model with a foreign key to it. (e.g.
Choice)
On the poll page, I want to show a list of the choices for the poll,
where each choice has a link to edit the choice, and there is also a
link to add a new choice. (for a new poll, there wouldn't be any
choices to start)
The link takes you to a choice page (or pops out a window page) where
you can edit or create the choice.
You hit OK on the choice page to come back to the poll page, which has
a list of choices that is updated with the new choice or the edited
choice.
You don't want to save the choice to the database until the poll is
saved (i.e. they can hit cancel and the poll and any changes to
choices are not saved.)

How to accomplish this "transaction" back and forth between the two
pages, where neither poll nor choices is saved until the Save button
is hit on the Poll page?  Specifically, how to pass the data between
the two pages without explicitly saving each choice to the DB?  Seems
like there is probably a standard mechanism for doing this.

Thanks,

Ben

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



Inverted checkbox value in modelForm field for BooleanField?

2011-05-14 Thread br
Conceptually, an interface element of my application can either be
click through (i.e. requires user interaction) or auto-cycle (no user
interaction).  So its boolean.  But i picked the wrong one when I
originally designed the model and now we have existing data and I
don't want to change it.

So I have a database field

class MyModel(Model):
 click_through = models.BooleanField(
 . . . )

And a modelform:

class MyForm(ModelForm):

class Meta:
model = MyModel
fields = ('name', 'click_through')

However, come interface tweaking time (now), we decided we want to
display a page with a check box "Auto Cycle?" instead of "click-
through", so I basically need to invert the actual value with respect
to this interface .

What is the easiest way to implement this?

I realize i could create a custom Field class and override to_python
to invert the value after the Form is submitted, but how about
inverting the value after i initiall load an instance of the value and
before it goes into the form, so that it displays a checked box if
click-through is False and vice-versa?  Is there an override similar
to to_python for this, or is there another way of going about it?


Thanks,

Ben

-- 
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: form new versus edit

2011-05-14 Thread br
My HTML guy and designer tend to get together to do some fancy stuff
(read: pain in the butt) so sometimes I need to access the data that a
model form field represents and can't just let django render it, which
is obviously the preferred way and I go that way if possible.  I am
pretty knew to this, but i figured that a custom tag filter could do
the trick, given that the data is in different places for an unbound
model form vs a form that is bound.  (would be a nice feature to have
one variable or attribute to access that would always have it, but
there seems to be resistance to this.)  This seems to work for my use
cases, but I haven't tested extensively so use at your own risk and
YMMV.  (put this in a python file in a templatetags directory in your
app and make sure you load the tags . . .read the docs)

@register.filter(name='modelform_field_value')
def modelform_field_value(value, arg):
"""
Usage: | model_field_value : ""
Returns the value of a field in a ModelForm, regardless of whether
the ModelForm was loaded with a Model Instance or with POST data
"""

form = value
field_name = arg
try:
if form.data.get(field_name) != None:
return  getattr(form.data, field_name)
# post data takes priority over instance data (this is useful
when is_valid is false and a form is returned to the template for
errors to be displayed, wherein both form and instance exist, but the
post is the most recent)
else:
return getattr(form.instance, field_name)
except Exception as e:
logger.error("Error in modelform_field_value tag.  Unable to
get value for field %s in form %s. \n%s"  %(field_name, form, str(e))
return "" # Best to log the error and display nothing than
letting the server throw a 500 or putting up something incorrect.

As far as getting the id in a hidden field,

you can use something like when you define your form:

class MyForm:

class Meta:
model = MyModel
fields = ('id', )
widgets = {
  'id': HiddenInput(),
 
}

or you could do something like this:

id  = IntegerField(
   widget = HiddenInput (attrs = {'class':'some-
class'}))


My experience has been that working with forms was the most
challenging part of Django to learn, decipher and figure out,
particularly if you don't want to let django render forms in a
default, simple way, which if you're working with Web 2.0 mentality
designers, where everything is "ajaxy", is rarely the case.  But after
learning enough to make django forms work for me with their designs, i
highly recommend defining your fields on the django side, because it
makes all of the backend stuff: processing, validation, writing to db,
etc. etc.  so so much easier and less error prone.  I typically only
use the above tag if i am just rendering some static text or anchor
tag, or checking if a value exists or equals something in template tag
logic. If its a form element, i try to define it in django.

Ben


On May 14, 4:45 pm, Greg Donald  wrote:
> On Sat, May 14, 2011 at 5:20 PM, Shawn Milochik  wrote:
> > One way:
>
> > class CustomCharField(forms.CharField):
>
> >     def __init__(self, *args, **kwargs):
>
> >     super(CustomCharField, self).__init__(*args, **kwargs)
>
> >     self.widget=forms.TextInput(attrs={ 'class':'myclass' })
>
> > class MyForm(forms.Form):
>
> >     field1 = forms.CustomCharField()
> >     field2 = forms.CustomCharField()
>
> Thank you.
>
> What is the convention for getting a pk id into a hidden form field?
>
> Since {{ form.name }} is the convention for getting my name field HTML
> rendered, I naturally tried {{ form.id }}, but it doesn't seem to know
> about Django conventions I don't guess.
>
> --
> Greg Donald
> destiney.com | gregdonald.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: M2M Ordering in Admin

2011-04-26 Thread br
Just found this:

http://pypi.python.org/pypi/django-sortedm2m/0.3.2

It looks awesome.  Thanks, Gregor.

Going to try it out. Will post back if I have problems.

br

On Apr 26, 9:06 am, br <robert...@gmail.com> wrote:
> I am creating an application for displaying decks of slides.   Each
> slide may be in more than one deck.  Order of the slides in a deck
> matters.   So, I have a many to many relation.
>
> class Slide(BaseModel):
>     """Represents a slide in a slide deck for a display""
>
> class Deck(BaseModel):
>     name = models.CharField(max_length = 45, unique=True  )
>     slides = models.ManyToManyField(Slide, through='DeckSlides')
>
>  class DeckSlides(BaseModel):
>     deck = models.ForeignKey(SlideDeck)
>     slide     = models.ForeignKey(Slide)
>     slide_position    = models.PositiveSmallIntegerField()
>
> I am trying to figure out how I can use Admin to both select slides
> for a deck (which is already provided by the default M2M control) and
> set the ordering of the slides in the Deck (not provided by default
> for an M2M in admin).  I'm guessing people have had to face this
> before. I've googled it but am not finding a solution.
>
> Thanks
>
> br

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



M2M Ordering in Admin

2011-04-26 Thread br
I am creating an application for displaying decks of slides.   Each
slide may be in more than one deck.  Order of the slides in a deck
matters.   So, I have a many to many relation.

class Slide(BaseModel):
"""Represents a slide in a slide deck for a display""

class Deck(BaseModel):
name = models.CharField(max_length = 45, unique=True  )
slides = models.ManyToManyField(Slide, through='DeckSlides')

 class DeckSlides(BaseModel):
deck = models.ForeignKey(SlideDeck)
slide = models.ForeignKey(Slide)
slide_position= models.PositiveSmallIntegerField()

I am trying to figure out how I can use Admin to both select slides
for a deck (which is already provided by the default M2M control) and
set the ordering of the slides in the Deck (not provided by default
for an M2M in admin).  I'm guessing people have had to face this
before. I've googled it but am not finding a solution.

Thanks

br

-- 
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: Django projects, apps, and git repos

2011-03-16 Thread br
Thanks for the feedback.  I've looked at git submodules and think that
will be a useful tool in django projects that share apps, once I'm
comfortable with the submodule functionality & understand how it fits
in with my prjoects.  And once I get my apps so they actually are in
fact "pluggable" (not there yet) I'll be looking at making them
installable with pip via pypi.

In the mean time, I've thought through our site and how i want to
structure the projects & repos and thought I would share what I've
come up with.

Basically what I've come up with for our specific scenario, is a
realization that our site consists of three or four distinct
"projects" or Applications (not talking about django apps) with fairly
distinct and modular sets of functionalities. Within each of these
projects will be various django apps, which i would like to make as
pluggable as possible. Our client users will need to have access to
each of the Applications (corresponding to the projects) from a
central dashboard, with a corresponding wrapper templates.  So in
addition to each separate Application project, I a have a "glue"
project that includes the general site functionality (e.g., user
accounts & permissions, wrapper templates, etc.) For now, I'm setting
up each project as its own repository, since releases might be
different for each one, and I want the projects themselves, in
addition to their apps, to be fairly pluggable, and even stand on
their own as deployable sites. The "glue" project for the dashboard &
common functionality will have a settings.py for the whole site, which
is cognizant of all the included projects, although individual
projects will have their own settings.py that can be used to deploy
them individually.  We'll see how this set up goes.

btw, I'm using virtualenv & pip for managing site-packages & external
packages, and using Fabric for deploying to development, staging,
production virtual hosts. I've currently set it up so each project has
its own corresponding virtualenv environment and fabric script but
haven't quite figured the long term vision for all of this out yet
since i'm still familiarizing myself with the different tools.  If
someone sees any pitfalls to be aware of, let me know.

Any feedback is, of course, welcomed.

Thanks,

Ben

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



Django projects, apps, and git repos

2011-03-14 Thread br
I have a question about how people relate django projects & apps
(including django apps that are shared between projects) to git
repositories.

We are using a gitolite setup on a central server to share
repositories between developers.

Right now we have two different projects, each with a corresponding
git repo, which function as standalone sites.  I am evolving one of
the two sites to basically "merge" the two projects and include
several apps from both. For now I am just leaving the repositories
separate, and setting up the master project to include apps from the
other project in settings.py and make sure they end up in the
PYTHONPATH, which seems to work.

As this stands, different apps pertain to different repos, even though
I am using them all in the same project.  I am not yet completely
comfortable with this setup, and am wondering how people usually
manage their  git repositories with respect to their projects and
apps, while dealing with shared apps and remaining true to DRY
principles?  Do you use a 1 to 1 repo-to-project relationship? Or do
you have multiple projects in 1 repo? Or do you have a different
directory & corresponding repo for all shared apps, and then a repo
for each project and corresponding project-specific files and apps?
or just 1 centralized repo for all your django projects? Something
else?

Just curious if there is a best way to manage this both from a project-
management and a git perspective.

Thanks

br

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



Skinning/extending the admin for sub-admin interfaces?

2011-03-10 Thread br
So I'm taking over a project (which already has a strong start in
Django) from a few guys. I'm new to the framework (but experienced as
a programmer) and excited for everything about it (the project,
Python, and Django).

I have one general design question. But first, some background

The site is something we will be providing as SaaS to various
customers (lets call them units) for interfacing with their own
customers.  Each unit will have various sub-units. So we are dealing
with a product having several web interfaces, with varying levels of r/
w access to data:

The interfaces:

- sys admin (Default Django Admin: my co.)

- unit dashboard (i.e. unit admin): (can edit data related to their
specific unit)

- sub-unit dashboard: (can edit a little bit of data, specific to
their subunit)

- authenticated public interface (subunit's customers)
- unauthenticated public interface

We're working on pretty designs for everything but the sysadmin, for
which we're stoked to be using Django admin.

So the question is, for each of the "dashboards"--which are
essentially limited admin interfaces--would it make sense to extend or
inherit from Django Admin in some way? Or should I just design these
like I would client-side pages, with specific forms to edit the
pertinent data that a user has permission to edit.

I realize this may be a total noob question, but I wanted to get a
general idea of which tree to start barking up from an architecture
standpoint

Thanks,

bdr

-- 
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 can I add the Openid session data to the Django test client Client.post() ?

2010-02-25 Thread br...@instantdirectmarketing.com
I looked at how the Django test client class method, Client.login()
stored sessions and attempt to copy the important sections into the
test so the session data could be stored.

When I broke into the test immediately before Client.post() was called
and the session looked OK.
ipdb> request.session.__dict__
{'_session_cache': {'openid': 'https://www.google.com/accounts/o8/id?
id=ItsAFakeOpenID'}, '_session_key':
'decee0b0bdbba7ad7c1a6601bbc60ef1', 'modified': True, 'accessed':
True}

However, after Client.post() the session doesn't seem to contain the
request.session['openid'] any longer.
I broke into the register view and checked:
ipdb> request.session.__dict__
{'_session_cache': {'pagesize': 10}, '_session_key': None, 'modified':
True, 'accessed': True}

Why is the session data not persisting?

class UserTestCAse(TestCase):
def test_register_should_create_UserProfile(self):
from django.test.client import Client
c = Client()

# Create a fake request to store session details.
from django.http import HttpRequest
request = HttpRequest()
from django.contrib.sessions.backends.db import SessionStore
request.session = SessionStore()

request.session['openid'] = 'https://www.google.com/accounts/
o8/id?id=ItsAFakeOpenID'
request.session.save()

response = c.post('/account/register/', {u'username':
[u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount':
[u'Signup']})
self.assertEqual(response.status_code, 200)
user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())

On Feb 24, 5:12 pm, "br...@instantdirectmarketing.com"
<bryan.wheel...@gmail.com> wrote:
> I'm trying to test that a UserProfile model is created as a new User
> is registered in django_authopenid.
> I don't understand how to add the Openidsessiondata to the POST.
>
>     class UserTestCase(TestCase):
>       def test_register_should_create_UserProfile(self):
>         from django.test.client import Client
>         c = Client()
>         response = c.post('/account/register/', {u'username':
> [u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount':
> [u'Signup']},)
>
>         self.assertEqual(response.status_code, 302)
>
>         user = User.objects.get( username ='john')
>         self.assertTrue(user.get_profile())
>
> I'm using django_authopenid and I want to make sure a UserProfile is
> created after the User is created.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 can I add the Openid session data to the Django test client Client.post() ?

2010-02-24 Thread br...@instantdirectmarketing.com
I'm trying to test that a UserProfile model is created as a new User
is registered in django_authopenid.
I don't understand how to add the Openid session data to the POST.

class UserTestCase(TestCase):
  def test_register_should_create_UserProfile(self):
from django.test.client import Client
c = Client()
response = c.post('/account/register/', {u'username':
[u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount':
[u'Signup']},)

self.assertEqual(response.status_code, 302)

user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())

I'm using django_authopenid and I want to make sure a UserProfile is
created after the User is created.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 can _meta.local_fields not match the table schema in the database?

2010-02-07 Thread br...@instantdirectmarketing.com
I'm completely confused about why _meta.local_fields returns more
fields than the database table contains. The User model inherits from
contrib.auth.models.User.


$ mysql -u user -p database
Enter password:
Reading table information for completion of table and column
names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1240032
Server version: 5.0.77 Source distribution

mysql> describe auth_user;
++--+--+-+-
++
| Field  | Type | Null | Key | Default |
Extra  |
++--+--+-+-
++
| id | int(11)  | NO   | PRI | NULL|
auto_increment |
| username   | varchar(30)  | NO   | UNI | NULL
||
| first_name | varchar(30)  | NO   | | NULL
||
| last_name  | varchar(30)  | NO   | | NULL
||
| email  | varchar(75)  | NO   | | NULL
||
| password   | varchar(128) | NO   | | NULL
||
| is_staff   | tinyint(1)   | NO   | | NULL
||
| is_active  | tinyint(1)   | NO   | | NULL
||
| is_superuser   | tinyint(1)   | NO   | | NULL
||
| last_login | datetime | NO   | | NULL
||
| date_joined| datetime | NO   | | NULL
||
| email_isvalid  | tinyint(1)   | NO   | | NULL
||
| email_key  | varchar(16)  | YES  | | NULL
||
| reputation | int(10) unsigned | NO   | | NULL
||
| gravatar   | varchar(32)  | NO   | | NULL
||
| gold   | smallint(6)  | NO   | | NULL
||
| silver | smallint(6)  | NO   | | NULL
||
| bronze | smallint(6)  | NO   | | NULL
||
| questions_per_page | smallint(6)  | NO   | | NULL
||
| last_seen  | datetime | NO   | | NULL
||
| real_name  | varchar(100) | NO   | | NULL
||
| website| varchar(200) | NO   | | NULL
||
| location   | varchar(100) | NO   | | NULL
||
| date_of_birth  | date | YES  | | NULL
||
| about  | longtext | NO   | | NULL
||
++--+--+-+-
++
25 rows in set (0.00 sec)


>From the Django error page, this is the SQL statement that generates
the error:   Exception Value: (1110, "Column 'about' specified twice")

'INSERT INTO `auth_user` (`username`, `first_name`, `last_name`,
`email`, `password`, `is_staff`, `is_active`, `is_superuser`,
`last_login`, `date_joined`, `email_isvalid`, `email_key`,
`reputation`, `gravatar`, `gold`, `silver`, `bronze`,
`questions_per_page`, `last_seen`, `real_name`, `website`, `location`,
`date_of_birth`, `about`, `email_isvalid`, `email_key`, `reputation`,
`gravatar`, `gold`, `silver`, `bronze`, `questions_per_page`,
`last_seen`, `real_name`, `website`, `location`, `date_of_birth`,
`about`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s)'

This SQL statement seems to be generated by iterating over
User._meta.local_fields.
I don't understand why _meta.local_fields doesn't match the actual
User table schema.

$ python2.5 manage.py shell
Python 2.5.4 (r254:67916, Aug  5 2009, 12:42:40)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
(InteractiveConsole)
>>> from forum.models import User
>>> len(User._meta.local_fields)
39
>>> import pprint
>>> pprint.pprint(User._meta.local_fields)
[,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 # here is where customizations to User begin.
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 # this seems to be a duplicate of the fields added to User
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
 ]
>>>

This is how this project customized User:

from django.contrib.auth.models import User

The additional fields to the model are added thusly:

User.add_to_class('email_isvalid',
models.BooleanField(default=False))

Re: Amazon Product Advertising API

2009-08-01 Thread br...@instantdirectmarketing.com

Luke,
I was curious how this was going.

I did find this:
http://jjinux.blogspot.com/2009/06/python-amazon-product-advertising-api.html

import time
import urllib

from boto.connection import AWSQueryConnection

AWS_ACCESS_KEY_ID = '...'
AWS_ASSOCIATE_TAG = '...'
AWS_SECRET_ACCESS_KEY = '...'


search_index = 'All'
keywords = 'pink'
aws_conn = AWSQueryConnection(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, is_secure=False,
host='ecs.amazonaws.com')
aws_conn.SignatureVersion = '2'
params = dict(
Service='AWSECommerceService',
Version='2008-08-19',
SignatureVersion=aws_conn.SignatureVersion,
AWSAccessKeyId=AWS_ACCESS_KEY_ID,
AssociateTag=AWS_ASSOCIATE_TAG,
Operation='ItemSearch',
SearchIndex=search_index,
Keywords=keywords,
ResponseGroup='ItemAttributes,Images',
Order='salesrank',
Timestamp=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()))
verb = 'GET'
path = '/onca/xml'
qs, signature = aws_conn.get_signature(params, verb, path)
qs = path + '?' + qs + '=' + urllib.quote(signature)
print "verb:", verb, "qs:", qs
response = aws_conn._mexe(verb, qs, None, headers={})
print response.read()



On Jul 17, 8:34 am, Luke Seelenbinder  wrote:
> I'm working on a django project right now that uses the Amazon Product
> Advertising API. I was using pyaws, but it is quite outdated and won't
> be useful for the changes coming in the next month.
>
> My first question is whether you know of any other python library for
> it.
> Second question, is there anybody willing to help me develop a new
> python abstraction for the api.
>
> I'm going to get started today with a new python api, if there is
> anybody willing to help, drop me an email (lukeqsee at gmail), or just
> reply to this message.
>
> Thanks,
> Luke
--~--~-~--~~~---~--~~
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: Developing a flexible CMS

2007-06-29 Thread anderson . santos . br

Hello everyone, I am talking to a friend to find a good solution for
this question and finally write our own CMS. I am really thinking
about how to create a flexible CMS and don't break django or don't
rework a lot of stuff.
So, what I do believe is that we have to focus on a Management System
then Content, and a flexible system should be able to go as far as we
want.
So, I like the idea of a page, but I do believe that a "portlet" is
more useful then a page content. So, with this in mind, we have to
think about a subapplication to be shown on a page, and not a bit of a
rock to put on the screen. But, of course, the simplest portlet will
be just a "content-link", but if I want something more complex, I can
do it and without the necessity of to write a new template tag,
because, if I am not a programmer I will get stucked and Django
solution won't be my solution.

A CMS is to make my website easier to grow, and not to create
barriers.

And about managing multiple objects of a model, we MUST remember that
THERE IS Django's  Manager and that's what we have to work on. So, I
think that our answer for this question resides on there. Django is
flexible, powerful, but "young" and don't have "much" automated
because WE don't know the perfect solution yet. But I don't believe it
will be far from the actual implementation.

Not rework, but improve Django, that's the way for a Real django
powered CMS that I would like to see.





On 27 jun, 01:03, sime <[EMAIL PROTECTED]> wrote:
> Hi Kyle, I've run into the same problems before. I think you'll find
> Django admin is great for simple operations involving single records
> and the most basic relations. But for anything beyond that, you'll
> probably need to roll your own admin page.
>
> On Jun 25, 1:15 am, Kyle Fox <[EMAIL PROTECTED]> wrote:
>
> > I hope I can explain this well, because I've been wracking my poor
> > little brain trying to figure out how to do this :)
>
> > I'm trying to create a flexible CMS.  I want it to be easy for users
> > to create a Page, and attach all kinds of content ("components") to
> > that page.  These components would all be Model classes.  Here are two
> > simple examples of the components I had in mind:
>
> > class TextSnippet(models.Model):
> > body = models.TextField()
>
> > class Photo(models.Model):
> > image = models.ImageField(upload_to="photos")
>
> > The idea is that a user add an arbitrary number of these components to
> > a Page model.  A Page model is nothing more than a container to hold
> > components, and a URL associated with the Page, something like:
>
> > class Page(models.Model):
> > url = models.CharField( maxlength=100, unique=True,
> > validator_list=[validators.isAlphaNumericURL])
>
> > The problem is that I can't figure out a good way to associate
> > instances of TextSnippet and Photo with a page.  It's obviously a many-
> > to-many between the components and pages (a component like a photo can
> > be on many pages, and a page can have many components), but I also
> > need to store more information about that particular page-component
> > relationship, for example a IntegerField that specifies the
> > component's position on that page.  Here's what I've come up with so
> > far:
>
> > class PageComponent(models.Model):
> > page = models.ForeignKey(Page, related_name="components",
> > edit_inline=models.TABULAR)
> > content_type = models.ForeignKey(ContentType)
> > object_id = models.IntegerField(core=True)
> > position = models.IntegerField(default=0, blank=True)
>
> > It "works" not too bad.  Conceptually (from the shell), I think it
> > does what I want.  However, I'm having a HECK of a time getting the
> > Page form in the admin to work in an intuitive way.  When adding
> > components to a page, the user sees a drop-down list of content_types,
> > and has to enter an object_id.  It works for me because I know what to
> > put for the object_id, but a regular user wouldn't
>
> > I think this would require me to write a custom form class for adding
> > and editing a page, but with these relationships I really don't even
> > know where to begin :S
>
> > If anyone can provide advice (or just flat out tell me if I'm thinking
> > about this wrong), it would be much appreciated!
>
> > Thanks,
> > Kyle


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---