Am I using static files "wrong"?

2012-10-04 Thread Micah Carrick
Regarding Django 1.4...

I recently came across a post that suggests that the way I'm managing
static files is "wrong". I wanted to make sure I'm clear on things.

In development, static files are in the "static" folders both within apps
at the project level. STATIC_URL = '/static/'

When I deploy a project, the collectstatic command copies *from* these
directories to a public folder on my static asset domain. STATIC_URL = '
http://static.foobar.com/', STATIC_ROOT = "/var/www/static.foobar.com"

Therefore, the "static" folder in my project directory is added to
STATICFILES_DIRS. Is that wrong? It was suggested that I'm supposed to be
collecting static files *to* the "static" folder--but that seems strange to
me as I don't want to collect static assets into my version controlled
source tree.

Secondly, I've heard that we should be using the static template tag and
not the STATIC_URL context variable. I see the advantages of using the
template tag, but, it's not wrong to use STATIC_URL right? It's not
deprecated or anything?

Cheers,
- Micah

-- 
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: When is a good time to use db_index? Rule of thumb?

2011-09-15 Thread Micah Carrick
As an oversimplification.. any time you will be looking up a record based on
a field, then you want an index on that (or those) fields. If you're finding
a row based on a slug, you want to index that slug field.

A good tool is to use the Django debug toolbar. When you load a page you can
take a look at the SQL queries. You can then use the 'dbshell' management
command to open up your database shell. Then you can then add "EXPLAIN "
before the SELECT queries to see how it's finding your data. Do a google
search on your database indexes and you'll find all sorts of details.

On Thu, Sep 15, 2011 at 8:38 PM, Micky Hulse  wrote:

> Hello,
>
> I have been using this great category/tag model:
>
> https://github.com/praekelt/django-category/blob/master/category/models.py
>
> ... and I noticed that the author added a db_index on the SlugField of
> the Category model.
>
> I hate to admit it, but I don't think I have ever explicitly used
> db_index parameter on any of my models.
>
> When's a good time to use db_index? Is there a general rule of thumb
> when coding Django models?
>
> Sorry if silly question.
>
> Thanks so much!
>
> Cheers,
> Micky
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: refreshing a page loaded via POST

2011-09-14 Thread Micah Carrick
After you successfully process a POST request, you can use a redirect to
send the user back to the orginal page.

On Wed, Sep 14, 2011 at 4:24 AM, Tom Evans  wrote:

> On Wed, Sep 14, 2011 at 8:12 AM, mohammed safeer.mtp
>  wrote:
> > if a user hits “Refresh” on a page that was loaded via POST, that request
> is
> > be repeated.
> > is there any remedy for this problem??
> >
>
> Yes, don't load the page via POST.
>
> POST requests are meant to be used for data modifying requests, which
> is why all user agents prompt you whether you really want to resubmit
> the request. GET requests are not meant to be used for data modifying
> requests, which is why they don't prompt you.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Using gedit for django development

2011-09-12 Thread Micah Carrick
I've written a blog post on using gedit, the default text editor in GNOME,
as a Django IDE. If you're a Linux user and you've never considered using
gedit for development then this may be an interesting read for you.

http://www.micahcarrick.com/gedit-as-a-django-ide-for-linux.html

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



Use of threading.local() ... what is the risk?

2011-09-10 Thread Micah Carrick
I have read https://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser and
numerous other discussions about the use of threading.local() yet I still
see it being employed in various projects.

I have recently implemented a referral system in which the use of
threading.local() makes the app very portable and very simple as I can
simply use the post_save signal (which cannot access the session). What I'm
doing...

1. When a user first gets to the site, middleware stores the referral ID
found in the URL and puts it into a session variable.
2. The session variable is copied to a threading.local() variable on every
request.
3. A handler for the post_save on the User model checks this
threading.local() variable, finds the User the referral code belongs to, and
associates the referral user with the referred user in referral model. This
handler also creates the referral code for the new user.

I like this approach because there is no need to think about the referral
system in the views, forms, or models of the auth system. I haven't deployed
this because of the big threading.local() warnings.

So this referral code is the only thing vulnerable here. This code is a
uniquely generated code which is associated with a User. What risks does
this pose and why?

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

2011-09-07 Thread Micah Carrick
For those of you working in GNOME 3 on Linux, I just put a new plugin up on
GitHub for managing django projects from within Gedit. I haven't done much
testing yet, so watch that repo for commits over the next few weeks while
I'm working on a large Django project.

https://github.com/Quixotix/gedit-django-project

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

2011-04-01 Thread Micah Carrick
No problem. ;)

On Fri, Apr 1, 2011 at 4:17 AM, Venkatraman S <venka...@gmail.com> wrote:

>
> On Wed, Mar 30, 2011 at 12:19 AM, Micah Carrick <mi...@greentackle.com>wrote:
>
>> I have used Authorize.Net for years and don't have a single complaint.
>> For Python/Django interfacing to Authorize.Net, Quantam, or PsiGate I
>> use quix.pay, which I also wrote: http://pypi.python.org/pypi/quix.pay/
>>
>
> Thanks Micah for this :
> http://www.micahcarrick.com/authorize.net-credit-card-form-django.html ;)
>
> --
> 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.
>



-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

-- 
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: DjangoCon US 2011

2011-03-31 Thread Micah Carrick
I was wondering about that too seeing as how I live in Portland.

On Thu, Mar 31, 2011 at 11:49 AM, Vinicius Mendes wrote:

> Hi, I am planing to go to DjangoCon US 2011 announced in this blog post:
> http://www.djangoproject.com/weblog/2010/nov/22/djangocon-us-2011/ but
> it's an old post and I haven't seen any other posts about it since this
> announcement. Will this event take place? Or it will be only the DjangoCon
> Europe?
>
> Atenciosamente,
> Vinicius Mendes
> Engenheiro de Computação
> Globo.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.
>

-- 
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: about url tag

2011-03-31 Thread Micah Carrick
You have created a "Named URL pattern". Check out:
http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns

On Thu, Mar 31, 2011 at 9:50 AM, Lic. José M. Rodriguez Bacallao <
jmr...@gmail.com> wrote:

> well, I don't know if this is ok, but I solved the problem adding a
> name='help_subject' tu the urlconf line
>
> On Thu, Mar 31, 2011 at 12:37 PM, Lic. José M. Rodriguez Bacallao
>  wrote:
> > sorry, I have atypo in the previous code, this is the las line:
> >
> > (r'(?P[0-9A-Za-z-]+)', HelpSubject.as_view()),
> >
> > On Thu, Mar 31, 2011 at 12:36 PM, Lic. José M. Rodriguez Bacallao
> >  wrote:
> >> I am getting a this error:
> >> TemplateSyntaxError at /help/
> >>
> >> Caught NoReverseMatch while rendering: Reverse for
> >> 'apps.help.views.HelpSubject.as_view()' with arguments '()' and
> >> keyword arguments '{'slug': u'gdsgdgdg'}' not found.
> >>
> >> On Thu, Mar 31, 2011 at 12:33 PM, Lic. José M. Rodriguez Bacallao
> >>  wrote:
> >>> I mean url tag: {% url ... %}
> >>>
> >>> this is what I am using: Leer
> >>> mas...
> >>>
> >>> directory structure:
> >>>
> >>> site
> >>>  |--> url.py
> >>>  |--> apps (included in the python path)
> >>>|--> help
> >>>   |--> models.py
> >>>   |--> views.py
> >>>   |--> urls.py
> >>>
> >>> where:
> >>> "apps" is a package (is in the python path)
> >>> "help" is my application
> >>> "HelpSubject" is a class based view, here is the definition:
> >>>
> >>>
> >>> class HelpSubject(DetailView):
> >>>template_name = 'help/help_subject.html'
> >>>context_object_name = 'help_subject'
> >>>queryset = HelpSubject.objects.filter(published=True)
> >>>
> >>> and here is the two lines in url.py and apps/help/url.py
> >>>
> >>> url.py:
> >>> (r'^help/', include('help.urls')),
> >>>
> >>> apps/help/url.py:
> >>> (r'(?P[0-9A-Za-z-]+)', help.HelpSubject.as_view,
> >>>
> >>> 2011/3/31 Łukasz Rekucki :
>  On 31 March 2011 17:16, Lic. José M. Rodriguez Bacallao
>   wrote:
> > use the tag:
> > url
> 
>  What do you mean by that ? Do you mean the {% url %} template tag, or
>  the `url` function commonly used in urls.py module. Give us some
>  examples of what you want to achieve and what problems you have.
>  --
>  Łukasz Rekucki
> 
>  --
>  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.
> 
> 
> >>>
> >>>
> >>>
> >>> --
> >>> Lic. José M. Rodriguez Bacallao
> >>> Centro de Biofisica Medica
> >>> -
> >>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
> mismo.
> >>>
> >>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> >>> por profesionales
> >>> -
> >>>
> >>
> >>
> >>
> >> --
> >> Lic. José M. Rodriguez Bacallao
> >> Centro de Biofisica Medica
> >> -
> >> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
> mismo.
> >>
> >> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> >> por profesionales
> >> -
> >>
> >
> >
> >
> > --
> > Lic. José M. Rodriguez Bacallao
> > Centro de Biofisica Medica
> > -
> > Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
> mismo.
> >
> > Recuerda: El arca de Noe fue construida por aficionados, el titanic
> > por profesionales
> > -
> >
>
>
>
> --
> Lic. José M. Rodriguez Bacallao
> Centro de Biofisica Medica
> -
> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
> mismo.
>
> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> por profesionales
> -
>
> --
> 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.
>
>


-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com 

 Email: mi...@greentackle.com
 Phone: 

Re: staticfile app question

2011-03-31 Thread Micah Carrick
I had to look up "grok". Guess I'm out of the loop.

Anyway, one other pitfall with using absolute URLs in CSS is that you can
break SSL (https) when you have common CSS for both the SSL and non-SSL
pages. So watch out for that. IMO, relative URLs are preferable in external
stylesheets. In fact, that has been a firm rule in most projects I've been
involved with.

-- 
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 send emails?

2011-03-30 Thread Micah Carrick
You can setup gmail in your settings.py

DEFAULT_FROM_EMAIL = 'your-email@your-domain'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'your-gmail-usern...@gmail.com'
EMAIL_HOST_PASSWORD = 'your-gmail-password'

And you can use the email_user() method of the models.User obejct:
http://docs.djangoproject.com/en/dev/topics/auth/

On Wed, Mar 30, 2011 at 5:53 AM, LIU Liang  wrote:

> Hello,
> I want to realize the verification of email when sign up. But I don't
> know how to send a email.
> for example with a account of gmail.
> I have tried the method following, but there's errors.
> Could anybody help?
>
> I create a django project, and add email configuration in settings.py.
> then
>python manage.py shell
> In [1]: from django.core.mail import send_mail
> In [2]: send_mail('Subject', 'Body of the message.',
> 'from_usern...@gmail.com',['to_usern...@gmail.com'])
>
> but...
>
> >>> from django.core.mail import send_mail
> >>> send_mail('Subject', 'Body of message.', 'mmhan...@gmail.com',
> ['mmhancxt@gm
> ail.com'])
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "D:\Python27\lib\site-packages\django\core\mail.py", line 407,
> in send_ma
> il
>connection=connection).send()
>  File "D:\Python27\lib\site-packages\django\core\mail.py", line 281,
> in send
>return self.get_connection(fail_silently).send_messages([self])
>  File "D:\Python27\lib\site-packages\django\core\mail.py", line 179,
> in send_me
> ssages
>new_conn_created = self.open()
>  File "D:\Python27\lib\site-packages\django\core\mail.py", line 144,
> in open
>local_hostname=DNS_NAME.get_fqdn())
>  File "D:\Python27\lib\smtplib.py", line 239, in __init__
>(code, msg) = self.connect(host, port)
>  File "D:\Python27\lib\smtplib.py", line 295, in connect
>self.sock = self._get_socket(host, port, self.timeout)
>  File "D:\Python27\lib\smtplib.py", line 273, in _get_socket
>return socket.create_connection((port, host), timeout)
>  File "D:\Python27\lib\socket.py", line 567, in create_connection
>raise error, msg
> error: [Errno 10060]
> >>>
>
> Thank you!
>
> --
> 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.
>
>


-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com 

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

-- 
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 hire a freelance Django developer

2011-03-29 Thread Micah Carrick
Hey folks,

Let me start by saying: Please don't email me your resume--this is not a job
listing.

That being said, I do need to hire python/django developers and system
admins from time to time to help me out with projects or take something off
my plate. Is there a good *free* resource to browse freelance Django
developers and/or post freelance gigs? I'm typically hiring somebody to help
with very small, open-source projects for which I am not trying to make
money off of. So paying $300 at github, stackoverflow, or any other paid job
posting site is not an option.

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

2011-03-29 Thread Micah Carrick
I have used Authorize.Net for years and don't have a single complaint.
For Python/Django interfacing to Authorize.Net, Quantam, or PsiGate I
use quix.pay, which I also wrote: http://pypi.python.org/pypi/quix.pay/

In testing quix.pay, I found that the Quantam gateway in authorize.net
emulation mode isn't bad. You can choose Quantam as the "free" gateway
with CDGCommerce if you have a lower sales and want to save on the
monthly gateway fee that Authroize.Net charges. Quantam was just a
little slower to respond than Authorize.Net but still quite
reasonable. I've been working on adding Paypal Web Payments Pro and
PayFlow into quix.pay and they certainly do the trick but I still
prefer Authorize.Net.

On Mar 12, 10:32 am, Malcolm  wrote:
> I recently used FeeFighters and they have a really awesome setup to
> help you compare and find merchant processors and gateways.  It's
> pretty neat because the merchant processors "bid" based on your
> preferences and all of their pricing is transparent and easy to
> understand.
>
> As for gateway, I am going with Authorize.net for my project.  PyPI
> has an authorize package for API integration and my developer found a
> django app at:https://github.com/zen4ever/django-authorizenet
>
> If interested in FeeFighters, please consider using my referral 
> link.https://feefighters.com/referral/d61fce3c6c274b38    :-)
>
> Malcolm
>
> On Mar 8, 6:43 pm, David Zhou  wrote:
>
>
>
>
>
>
>
> > I use Braintree, and it's been great.
>
> > -- dz
>
> > On Tue, Mar 8, 2011 at 4:40 PM, CLIFFORD ILKAY
>
> >  wrote:
> > > On 03/08/2011 09:59 AM, Bill Freeman wrote:
>
> > >> And I can't resist recommending solutions that don't require your to 
> > >> touch
> > >> the credit card number.  If you never had it, you can't be responsible 
> > >> for
> > >> compromising it.
>
> > > That is true. Most of thepaymentprocessors have some sort of hosted form
> > > solution for that. However, there are significant limitations in those
> > > hosted form solutions that may make them unsuitable in some situations. 
> > > For
> > > instance, we ran into one such limitation recently on a project where the
> > > processor apparently doesn't provide any sort of "success" or "failure"
> > > notification for zero dollar transactions. Why would you want a zero 
> > > dollar
> > > transaction you might be wondering? Our client was running a promotion 
> > > where
> > > some initial period was free after which the normal recurring fees would
> > > kick in. Normally, there is an initial fee and recurring fees. Upon 
> > > success
> > > or failure on the normal initial fee, we'd get a callback to a view 
> > > function
> > > from thepaymentgateway which we'd need to complete the transaction.
> > > Completion of the transaction consists of listing the product and updating
> > > the user's dashboard with the transaction date and the expiry date for the
> > > listing. With the zero dollar transaction, we never got a callback due so 
> > > we
> > > could do none of those things. We had to manually list the products and
> > > update the user's dashboard for the successful transactions in that
> > > scenario.
>
> > > To avoid creating a situation in the future where there would have to be
> > > tedious and error-prone manual processing, we recommended to the client 
> > > that
> > > they don't offer "free initial period" promotions but instead charge some
> > > nominal amount, even if it's one cent. "All listings one cent" doesn't 
> > > have
> > > quite the same impact as "Free listings" even though for all intents and
> > > purposes, it's the same thing. We've discovered many other limitations 
> > > like
> > > that, small and large, that really makes the case for API-level 
> > > integration,
> > > in which case you'd have to go through a PCI compliance audit. By the way,
> > > we've been through it multiple times. For the most part, it's perfunctory.
> > > --
> > > Regards,
>
> > > Clifford Ilkay
> > > Dinamis
> > > 1419-3266 Yonge St.
> > > Toronto, ON
> > > Canada  M4N 3P6
>
> > > 
> > > +1 416-410-3326
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

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



Re: Read-only fields and complex relationships in admin

2011-03-27 Thread Micah Carrick
Thank you Jacob. That's actually the answer I was hoping for.

On Fri, Mar 25, 2011 at 8:48 PM, Jacob Kaplan-Moss <ja...@jacobian.org>wrote:

> On Fri, Mar 25, 2011 at 6:39 PM, Micah Carrick <mi...@greentackle.com>
> wrote:
> > I have an application which handles a typical "checkout" process for an
> > e-commerce website. Orders from online customers end up in several models
> [... snip complex problem ...]
>
> > Anybody have any tips, links to articles, etc. that
> > might help me research the best approach for this project?
>
> Yes: don't use the admin for this.
>
> Really, I know it's tempting because the admin gives you like 50% of
> what you want for free. But trust me when I tell you that if you go
> down the path of trying to kludge the admin into supporting your
> custom workflow you will be very unhappy. You'll get to 90% very
> quickly, and then you'll spend a ridiculous amount of time trying to
> close the final gap. You never quite will, and your app won't "feel"
> right. Sooner or later you'll give up and write custom views from
> scratch, throwing away all that hard work.
>
> Really: I've seen this happen more times than I can count. Don't go
> down this path.
>
> Just write custom views. Try out some apps that reproduce certain
> admin features -- apps like django-tables
> (https://github.com/miracle2k/django-tables), django-filter
> (https://github.com/alex/django-filter), django-pagination
> (https://github.com/ericflo/django-pagination), and
> django.contrib.formwizard or perhaps django-formwizard
> (https://github.com/stephrdev/django-formwizard). They might save you
> a bit of time, but you'll save the most time by not trying to force
> the admin into doing something it's not good at.
>
> Jacob
>
> --
> 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.
>
>


-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Read-only fields and complex relationships in admin

2011-03-25 Thread Micah Carrick
I have an application which handles a typical "checkout" process for an
e-commerce website. Orders from online customers end up in several models
(order, billing/shipping address, line items, gateway data, shipments,
etc.). An administrator will have to be able to (a) create new orders
manually from the admin (b) change a select few fields in an order and/or
call methods on the model (c) view the entire order data in read-only mode .
Obviously this goes beyond what Django's out of the box admin can handle and
needs a custom interface.

That being said, I would like for this to work within the existing admin
interface, In other words, if I drop this checkout application into any
existing project, the order administration pages shows up in the regular
admin--just with my custom admin pages for those models rather than the
standard Django pages. I've never done this level of hacking/integrating
with Django's admin. Anybody have any tips, links to articles, etc. that
might help me research the best approach for this project?

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



Decoupling shopping cart from checkout

2011-03-16 Thread Micah Carrick
I have a Django app for a shopping cart, and another for checkout (checkout
form, payment gateway, order processing). I would really like for these to
be completely decoupled but am having a hard time coming up with a solution
that gives me a warm fuzzy feeling.

Here is a simplification:

Checkout is fed line item data (sku, description, qty, price) where a line
item might represent a product, shipping, tax, a discount--anything. This is
the only data checkout needs. Now, the cart has all of this information. So
my current implementations of these applications has the checkout app
depending on the cart to feed it that data. I would checkout to be able to
be fed the line items in a more generic abstract way, but, without having a
redundancy when the cart application is used with it.

I cannot feed checkout with data in a POST or session because you don't want
prices floating around where people could change them. So the data has to be
fed from the DB based on an id stored in the session (wow, that sounds a lot
like a cart, doesn't it!). The goal would be that I could pair the checkout
app with the cart app and it works like it does now, but, also be able to
use the checkout app on sites that don't need a cart at all (say, somebody
who sells one product, accepts donations, one event registration at a time,
etc).

Thoughts?

-- 
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: Can I sort a related model reference in a template?

2011-03-12 Thread Micah Carrick
Yeash. Don't know how I missed that. Thanks!

On Sat, Mar 12, 2011 at 5:27 AM, Shawn Milochik  wrote:

> You can put a sort order in the model's meta info. That way you'll always
> have a default sort.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Can I sort a related model reference in a template?

2011-03-12 Thread Micah Carrick
If I have a Product model which has a one-to-many relationship with
ProductImage model...

I can get the images in the template using product.productimage_set.all,
however, is there any way to sort that or will I instead have to query the
product images in the view?

-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com 

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

-- 
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: Generate a unique username for django.contrib.auth

2011-01-12 Thread Micah Carrick
Thanks folks.

Here's what I have now. Not the most elegant but it's the best I can come up
with so far. First, I'm generating a random string for the username so that
the form will validate. After the record is saved I change the username to
"user_" and the user ID. This way it looks a little less scary if it pops up
on an admin form somewhere or something.

# in the view for my sign up form
if request.method == 'POST':
data = request.POST.copy()
randstr = ''.join([choice(string.letters) for i in xrange(30)])
data['username'] = 'user_' + randstr
form = SignUpForm(data) # subclass of UserCreationForm
if form.is_valid():
form.save()

# in the save method of SignUpForm which is subclassed from UserCreationForm
user.save()
user.username = 'user_' + str(user.id)
user.save()

What I still hate about this one is that I'm hitting the database twice for
a single registration. But, it seems to work.

On Wed, Jan 12, 2011 at 1:23 PM, Eric Chamberlain <e...@rf.com> wrote:

> We use a base64 or base36 (if you want compatibility with the
> contrib.admin) encoded UUID, or generate a random 30-character string, the
> odds of a collision is quite low.
>
> On Jan 12, 2011, at 1:11 PM, Micah Carrick wrote:
>
> > I've got my site's authentication working with and email and password
> only--no username (thanks to Shawn Milochik for helping me with that).
> However, I still need to put in a username to make the User model happy. I
> was hoping to have "user" as a prefix and then some unique number.
> >
> > I cannot simply copy the email to the username because the username must
> be less than 30 characters and, after looking into my database, many email
> addresses go over that.
> > I cannot generate a random number because there could be a collision.
> > I cannot use uuid4().hex because that's 32 characters... I need <30.
> > I cannot use User.objects.count() because that could result in a
> collision if 2 users register at the same time.
> >
> > Thoughts?
> >
> >
> >
> >
> > --
> > 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<django-users%2bunsubscr...@googlegroups.com>
> .
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Micah Carrick, Founder

*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Generate a unique username for django.contrib.auth

2011-01-12 Thread Micah Carrick
I've got my site's authentication working with and email and password
only--no username (thanks to Shawn Milochik for helping me with that).
However, I still need to put in a username to make the User model happy. I
was hoping to have "user" as a prefix and then some unique number.

I cannot simply copy the email to the username because the username must be
less than 30 characters and, after looking into my database, many email
addresses go over that.
I cannot generate a random number because there could be a collision.
I cannot use uuid4().hex because that's 32 characters... I need <30.
I cannot use User.objects.count() because that could result in a collision
if 2 users register at the same time.

Thoughts?

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



Re: Email and activation key in django.contrib.auth

2011-01-12 Thread Micah Carrick
Shawn,

Thank you so very much. This is coming along quite nicely. Your answers have
been perfect.

On Wed, Jan 12, 2011 at 9:19 AM, Shawn Milochik <sh...@milochik.com> wrote:

> Without changing or subclassing the User model (which shouldn't be done,
> because it causes problems), I don't know how you can put the unique e-mail
> address constraint on the database, except manually via your database's own
> tool. I don't know if that can cause problems with Django's ORM, and it is
> probably a very complicated question with answers that differ greatly
> depending on the database backend and driver being used. So I can't offer
> any useful info here.
>
> However, on the front end you can certainly override the clean() methods of
> your fields, and gracefully handle checking of duplicates and user-friendly
> error messages. I know you like the DB constraints because it's a
> best-practice, but if no other software will be accessing your database then
> this is all you'll need.
>
> For your two questions:
>
> You don't need to remove the username from the ModelForm -- just don't
> include it in the template.
>Override the default template (copy the default template and modify your
> changed version).
>
> To change the label on the template, you can change the 'label' property of
> the field in your subclassed ModelForm.
>Something like this (in the __init__, after calling the __init__ of
> super():
>
>self.fields['username'].label = 'E-mail Address'
>
>
> Shawn
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Micah Carrick, Founder

*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Re: Email and activation key in django.contrib.auth

2011-01-12 Thread Micah Carrick
Ah yes, thanks again.

I tinkered with the django-registration and was a bit more than I need.

While the username can store an email address, it's 30 character limit
prevents me from relying on that. Looking over an existing database I have,
there are quite a few email addresses over that character limit. I suppose I
could check if an email exists before saving a user creation form, but I
don't like not having that constraint in the DB. Can I alter the DB field at
creation with a fixture or something? I guess then I wouldn't have that nice
DB abstraction.

I have created the custom auth backend to allow users to sign in with an
email address. It works great. I then subclassed the UserCreationForm to add
an email address field which also works. In this case, the web users will
not need access to the admin so I'm not too concerned about what username
shows up there--I could even auto-generate one. So now what I need to do is:

1. Remove the "username" field from my subclassed version of
UserCreationForm. Not sure how to do that. I will then create the username
in the save() method.
2. Rename the "username" field in the login form to "Email Address". I am
using the built-in login view, so I probably will have to write my own view?



On Wed, Jan 12, 2011 at 7:50 AM, Shawn Milochik <sh...@milochik.com> wrote:

> If you're using 1.3, you can make the e-mail address the username, which
> will automatically require it to be unique.
>
> I haven't used django-registration, but many others have, so maybe they'll
> be able to answer. On face-value, I'd say that your question is a bit off,
> though; django-registration doesn't replace the contrib.auth system. It just
> provides a way for you to create a user-friendly registration system for
> your users, but it still uses contrib.auth on the backend.
>
> Shawn
>
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Micah Carrick, Founder

*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Re: Email and activation key in django.contrib.auth

2011-01-12 Thread Micah Carrick
Thanks for the great information. I've tinkered with it and it seems to be
working pretty good. Still need to make the email unique but all in all a
pretty good solution.

What do you think about using django-registration instead? Does anybody know
of a pro/con comparison of the built-in auth versus django-registration?

On Tue, Jan 11, 2011 at 5:42 PM, Shawn Milochik <sh...@milochik.com> wrote:

> Yes, it's very easy to do.
>
> For the e-mail address as the login, all you have to do is create your own
> auth backend. That is a LOT simpler than it sounds -- just a few lines of
> code.
>
>
> http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend
>
> As for the need to activate their account, that's very simply handled in
> your custom auth backend, since you'll be writing it anyway. Just check for
> activation status in your custom authenticate function.
>
> Here's my "custom" auth backend. It uses the e-mail address for the login.
> You'll still have to give the User instance a unique username, but then you
> can ignore it. You can copy this verbatim and be done, other than
> "activating" the account, which you can easily work out.
>
> http://dpaste.com/hold/308215/
>
> Note: If you can work with the 1.3 beta (and eventually the final release),
> then you can just use the e-mail address as the username, as they've
> expanded the allowed characters in the username field of the User model.
> Chances are you can do that, since 1.3 is scheduled for final release in a
> few weeks.
>
> Shawn
>
>
>  --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Micah Carrick, Founder

*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Email and activation key in django.contrib.auth

2011-01-11 Thread Micah Carrick
Hey guys,

I've been looking into this for a few hours now and don't have a good
solution. I want to use the built in authentication system for a project.
However, it's essential that (a) users login using their email address and
password only (no username or username=email) and that (b) they must
"activate" their account via email containing an activation key.

This is a VERY common authentication paradigm and I can only assume I'm
missing something. I've seen many people with the same problem, however,
most responses seem to be hacks or very outdated. I'm relatively new to
Django (10 years PHP) and am hoping somebody has a link or a few vocabulary
words to point me in the right direction. Obviously I could implement this
myself, but, I really want to use the built-in auth system. DRY. I would
expect it to be relatively simple... override a few class methods or
something along those lines.

Any help would be much appreciated. Thanks!

-- 
Micah Carrick, Founder

*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com <http://www.greentackle.com>

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

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



Re: A Model to store links to other models

2010-11-22 Thread Micah Carrick
Hey guys,

I could use some advice on the next steps for the administration. I am
passing the link groups to the template via context so that the template can
iterate over each group creating a unordered list of links for each group.
Some links are blog posts, some are flat pages, etc. Works great. However,
there are two parts of the admin I could use some guidance on. Links to
docs, blogs, or example code would be great.

First, in the drop down list for the ContentType, I need to exclude any
object that do not define get_absolute_url. In other words, only models that
can be linked to should be allowed.

Second, and this may be more difficult, the object_id field requires the
admin user to know the PK of the object their linking to, which they most
certainly will not. However, I don't know how that could be determined
without first knowing which content_type they select-- AJAX is the only
thing I can think of. Thoughts?

class LinkGroup(models.Model):
site = models.ForeignKey(Site)
# template_var is the name of the list of links passed in context to
template
template_var = models.CharField(max_length=25, unique=True,
db_index=True)
heading = models.CharField(max_length=100, blank=True, null=True)

def __unicode__(self):
return self.template_key

class Meta():
db_table = 'link_group'

class LinkObject(models.Model):
text = models.CharField(max_length=50) # text for the link
link_group = models.ForeignKey(LinkGroup)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
sort_order = models.PositiveIntegerField(default=100)

def __unicode__(self):
return self.text

class Meta():
db_table = 'link_object'

class LinkGroupInline(admin.TabularInline):
model = LinkObject

class LinkGroupAdmin(admin.ModelAdmin):
inlines = [
LinkGroupInline
]

admin.site.register(LinkGroup, LinkGroupAdmin)

On Sat, Nov 20, 2010 at 5:17 AM, Micah Carrick <mi...@greentackle.com>wrote:

> I had not seen the generic relationships and ContentType. I'm going to play
> with that a bit.
>
> Thanks everybody!
>
> 2010/11/20 Łukasz Rekucki <lreku...@gmail.com>
>
> On 20 November 2010 02:51, Micah Carrick <mi...@greentackle.com> wrote:
>> > I'm having trouble coming up with a pretty solution to a seemingly
>> simple
>> > task. I'm relatively new to Django.
>> >
>> > I want to allow the end user to control various lists of links on the
>> site
>> > used for navigation. The admin should allow the creation of "link
>> groups"
>> > which have a collection of "links". These links would reference a
>> > pre-determined list of models. Let's say, for example, that there is a
>> "link
>> > group" created for the footer links of a website. In the admin section,
>> a
>> > user could add a link to a specific blog (from the Blog model), another
>> link
>> > to the about us page (flatpages), etc.
>> >
>> > In other words, I'm trying to associate individual records from a number
>> of
>> > tables together as a group of objects having a URL. I'm trying to find a
>> > nice, abstract solution. Obviously I don't want actual URLs in the
>> database.
>> > This is something I would use frequently so I want to see if I can find
>> or
>> > write an app to do this--if I can come up with an elegant solution.
>> >
>> > This would be nice, but, I can't imagine how it could be possible:
>> >
>> >
>> > class LinkGroup(models.Model):
>> > site = models.ForeignKey(Site)
>> > name = models.CharField()
>> >
>> > class Links(models.Model):
>> > link_group = ForeignKey(LinkGroup)
>> > model_type = ???
>> > model_id = ForeignKey() # no
>> can
>> > do!
>> > sort_order = PositiveIntegerField(default=100)
>> >
>> >
>> > This is an idea, however, I don't like having to reference the import in
>> the
>> > DB. It's just begging for problems.
>> >
>> >
>> > class LinkModel(models.Model):
>> > name = models.CharField() # such as "Flat Page"
>> > model = models.CharField() # such as "myapp.models.FlatPage"
>> >
>> > class LinkGroup(models.Model):
>> > site = models.ForeignKey(Site)
>> > name = models.CharField() # such as "Navigation Links"
>> >
>> > class Link(models.Model):
>> > text = CharField() # such as "About Us"
>> > link_

Re: A Model to store links to other models

2010-11-20 Thread Micah Carrick
I had not seen the generic relationships and ContentType. I'm going to play
with that a bit.

Thanks everybody!

2010/11/20 Łukasz Rekucki <lreku...@gmail.com>

> On 20 November 2010 02:51, Micah Carrick <mi...@greentackle.com> wrote:
> > I'm having trouble coming up with a pretty solution to a seemingly simple
> > task. I'm relatively new to Django.
> >
> > I want to allow the end user to control various lists of links on the
> site
> > used for navigation. The admin should allow the creation of "link groups"
> > which have a collection of "links". These links would reference a
> > pre-determined list of models. Let's say, for example, that there is a
> "link
> > group" created for the footer links of a website. In the admin section, a
> > user could add a link to a specific blog (from the Blog model), another
> link
> > to the about us page (flatpages), etc.
> >
> > In other words, I'm trying to associate individual records from a number
> of
> > tables together as a group of objects having a URL. I'm trying to find a
> > nice, abstract solution. Obviously I don't want actual URLs in the
> database.
> > This is something I would use frequently so I want to see if I can find
> or
> > write an app to do this--if I can come up with an elegant solution.
> >
> > This would be nice, but, I can't imagine how it could be possible:
> >
> >
> > class LinkGroup(models.Model):
> > site = models.ForeignKey(Site)
> > name = models.CharField()
> >
> > class Links(models.Model):
> > link_group = ForeignKey(LinkGroup)
> > model_type = ???
> > model_id = ForeignKey() # no
> can
> > do!
> > sort_order = PositiveIntegerField(default=100)
> >
> >
> > This is an idea, however, I don't like having to reference the import in
> the
> > DB. It's just begging for problems.
> >
> >
> > class LinkModel(models.Model):
> > name = models.CharField() # such as "Flat Page"
> > model = models.CharField() # such as "myapp.models.FlatPage"
> >
> > class LinkGroup(models.Model):
> > site = models.ForeignKey(Site)
> > name = models.CharField() # such as "Navigation Links"
> >
> > class Link(models.Model):
> > text = CharField() # such as "About Us"
> > link_group = ForeignKey(LinkGroup)
> > model = ForeignKey(LinkModel)
> > model_id = PositiveIntegerField() # such as the PK for the
> > myapp.models.FlatPage model
> > sort_order = PositiveIntegerField(default=100)
> >
> >
> > Any suggestions?
>
> You should checkout generic foreign keys[1]. It's a standard way of
> building models that need to reference rows in more then one table. So
> your models would be something like this:
>
> from django.contrib.contenttypes.models import ContentType
> from django.contrib.contenttypes import generic
>
> class LinkGroup(models.Model):
>site = models.ForeignKey(Site)
>name = models.CharField() # such as "Navigation Links"
>
> class Link(models.Model):
> link_group = ForeignKey(LinkGroup)
>content_type = models.ForeignKey(ContentType)
>object_id = models.PositiveIntegerField()
>linked_object = generic.GenericForeignKey('content_type', 'object_id')
>
>
> [1]:
> http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations
>
> --
> Łukasz Rekucki
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



A Model to store links to other models

2010-11-19 Thread Micah Carrick
I'm having trouble coming up with a pretty solution to a seemingly simple
task. I'm relatively new to Django.

I want to allow the end user to control various lists of links on the site
used for navigation. The admin should allow the creation of "link groups"
which have a collection of "links". These links would reference a
pre-determined list of models. Let's say, for example, that there is a "link
group" created for the footer links of a website. In the admin section, a
user could add a link to a specific blog (from the Blog model), another link
to the about us page (flatpages), etc.

In other words, I'm trying to associate individual records from a number of
tables together as a group of objects having a URL. I'm trying to find a
nice, abstract solution. Obviously I don't want actual URLs in the database.
This is something I would use frequently so I want to see if I can find or
write an app to do this--if I can come up with an elegant solution.

This would be nice, but, I can't imagine how it could be possible:


class LinkGroup(models.Model):
site = models.ForeignKey(Site)
name = models.CharField()

class Links(models.Model):
link_group = ForeignKey(LinkGroup)
model_type = ???
model_id = ForeignKey() # no can
do!
sort_order = PositiveIntegerField(default=100)


This is an idea, however, I don't like having to reference the import in the
DB. It's just begging for problems.


class LinkModel(models.Model):
name = models.CharField() # such as "Flat Page"
model = models.CharField() # such as "myapp.models.FlatPage"

class LinkGroup(models.Model):
site = models.ForeignKey(Site)
name = models.CharField() # such as "Navigation Links"

class Link(models.Model):
text = CharField() # such as "About Us"
link_group = ForeignKey(LinkGroup)
model = ForeignKey(LinkModel)
model_id = PositiveIntegerField() # such as the PK for the
myapp.models.FlatPage model
sort_order = PositiveIntegerField(default=100)


Any suggestions?

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