Clarification on __in when attribute on left is a many to many field

2018-01-15 Thread Jeff Tchang

In the documentation on this page:
https://docs.djangoproject.com/en/2.0/topics/db/examples/many_to_many/

you have the following example:

>>> Article.objects.filter(publications__in=[1,2]).distinct()>> [, >> Python>]>


Does the __in for many to many fields mean for ANY publication in [1,2]. So 
does Django go through every publication in every article and if any of them 
are in the list on the right that Article is included in the result?



-Jeff

-- 
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/331d1f73-ce56-4296-a9e3-bcbd033a1530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django; walking through djangoproject tutorial; can't get poll to work

2012-12-18 Thread Jeff Tchang
My first guess is that

{% for choice in poll.choice_set.all %}

is empty. So you have no choices attached to the poll. You can verify
this by looking at the generated HTML source and seeing if you have
any radio buttons at all. Since you said you didn't that is my guess.

I didn't go back and look at the tutorial but try creating some
choices for the poll.

-Jeff

On Tue, Dec 18, 2012 at 7:56 PM, Deron  wrote:
> Hi,
>
> First post here. I'm extremely new to Django and I have been fumbling my way
> through the DjangoProject "poll" app tutorial for a couple weeks now. I
> understand a lot of what's going on, but a lot of things are completely lost
> on me as well. That said, I'm to the point of actually using the poll app.
> I've created a view so you can view the poll, select a choice and then click
> "vote." Problem is, when I view the page (/polls/1/) I see my heading which
> is "What's Up?" and I see a "vote" input button, but no radio button. I'm
> not exactly sure why it's not showing up. Anyone want to take a shot in the
> dark on this one? Here's my "detail.html" view (copied straight from the
> tutorial):
>
> {{ poll.question }}
> {% if error_message %}{{ error_message }}{% endif %}
> 
> {% csrf_token %}
> {% for choice in poll.choice_set.all %}
>  value="{{ choice.id }}" />
> {{ choice.choice }} />
> {% endfor %}
> 
> 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/DtV-YM6VU44J.
> 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.



Django Friendly URLs

2012-08-25 Thread Jeff Tchang
Hey all. I've created a Django application that allows you to create
friendly/vanity urls:
https://github.com/tachang/django_friendlyurls

There is still a lot to be desired but it gets the basic job done. It works
by implementing a catch all URL string and then trying to figure out which
view to return.

-Jeff

-- 
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: Layout and global.css files

2012-08-22 Thread Jeff Tchang
I see some stuff under:

/python/lib/python2.6/site-packages/django/contrib/admin/static/admin/css


On Wed, Aug 22, 2012 at 6:41 PM, Gregory Strydom <
gregory.strydom...@gmail.com> wrote:

> Could anyone perhaps tell me where i could find the layout.css and
> global.css for the base admin site?
>
> Ive tried looking through C:/Python26/site-packages/django but cant seem
> to find anything. What i am trying to do is just change colour where it say
> Users, Groups, Sites etc in the django admin. I managed to change the
> header colors so far but was told i need to edit layout and global.css to
> change the other colors.
>
> Thanks very much for any help with this!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/N9aDIJzmHngJ.
> 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: View loaded twice / Database entry saved twice

2012-08-22 Thread Jeff Tchang
Is it possible you are testing using a browser and it is doing a request
for the page and for favicon.ico? That would end up being 2 requests. You
can use something like Chrome Developer Tools or Firebug to see.

-Jeff

On Tue, Aug 21, 2012 at 4:07 PM, James Verran  wrote:

> Hi there, I'm trying to capture all url path data. (Except admin, and a
> couple other paths.)
>
> At the end of my urls.py file, I'm using r'^(.*)$'... On my associated
> view, I make a simple entry into a database - ie:
> Test(path=capturedpath).save()
>
> The problem: my database entry is saved twice! Or rather, my view is being
> loaded twice. I added a global variable to check- if not
> globals()['already_saved']: Test(path=capturedpath).save()
>
> If I adjust the path: r'^test/(.*)$'  all works as expected (here my url
> would be 
> 'mysite.com/test/url/data/to/capture'
> .)
>
> I'm using django 1.4. Any help/thoughts/suggestions would be much
> appreciated.
>
> 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.
>

-- 
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: Problem with file upload!

2011-09-03 Thread Jeff Tchang
Can you verify that your request method is indeed a POST? Print it out
if necessary.

-Jeff

On Fri, Sep 2, 2011 at 10:39 AM, Ludvig  wrote:
> Hello,
>
> Usually only read these posts so i hope i'm doing this right!
>
> Recently my file upload just stopped working, and i've no idea what
> i've changed. I noticed that request.FILES is empty so i've googled
> some and cant figured out my problem.
>
> My form looks like this
>
>        
>            
>            
>        
> and my code like this,
>
>
> class PhotoUploadView(FormView):
>    template_name ="album/photo_upload.html"
>    form_class = PhotoUploadForm
>    def get_context_data(self,**kwargs):
>        context =
> super(PhotoUploadView,self).get_context_data(**kwargs)
>        context['user_info'] = self.request.user
>        if 'upload_form' in kwargs:
>            context['upload_form'] = kwargs['upload_form']
>        else:
>            context['upload_form'] = PhotoUploadForm()
>        album = get_object_or_404(Album,id=self.kwargs['album_id'])
>        context['album'] = album
>        return context
>
>    def form_valid(self,form):
>        print 'kek'
>    def post(self,*args,**kwargs):
>        print self.request.FILES
>        print self.request.raw_post_data
>        if self.request.method == "POST":
>            form =
> PhotoUploadForm(self.request.POST,self.request.FILES)
>            if form.is_valid():
>                photo = Photo()
>                photo.title = form.cleaned_data['title']
>                photo.summary = form.cleaned_data['description']
>                photo.album = get_object_or_404(Album,id =
> kwargs['album_id'])
>                photo.is_cover_photo = True
>                path =
> self.generate_filename(self.request.FILES['photo'].name,self.request.user,kwargs['album_id'])
>                destination = open(path,"wb+")
>                for chunk in self.request.FILES['photo'].chunks():
>                    destination.write(chunk)
>                destination.close()
>                photo.imagePath = path
>                photo.save()
>        return
> self.render_to_response(self.get_context_data(upload_form=form))
>
>    def generate_filename(self,filename,user,album_id):
>        filename = os.path.splitext(filename)[1]
>        return settings.MEDIA_ROOT + "/profiles/" + user.username +
> "/" + "albums/" + album_id + "/" + str(hashlib.md5(str(time.time() +
> user.id)).hexdigest()) + filename
>
>
> Also,  i'm a inexperienced programmer. Still only a hobby so be kind
> to me,
>
> 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.
>
>

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



Re: Setting up a PostGIS DB

2011-09-03 Thread Jeff Tchang
Have you ran:

psql -d yourdatabase -f postgis.sql

After you do this you should see 1 or 2 tables in your Postgres
database as well as a slew of sql functions. Make sure you've done
this and verify it.

-Jeff

On Thu, Sep 1, 2011 at 2:18 PM, Reinout van Rees  wrote:
>
> On 01-09-11 19:00, Dan H wrote:
>>
>> I am trying to set up a PostGIS DB in Django to track Lat/Lon of a
>> location, and use it with the Google Maps API. However when I try to
>> run 'python manage.py syncdb' after running 'createdb -T
>> template_postgis mydb' I get this error.
>>
>> Failed to install index for reviews.Location model: function
>> addgeometrycolumn(unknown, unknown, integer, unknown, integer) does
>> not exist
>> LINE 1: SELECT AddGeometryColumn('reviews_location', 'geometry',
>> 432...
>>                ^
>> HINT:  No function matches the given name and argument types. You
>> might need to add explicit type casts.
>>
>> Anyone have any advice or ideas?
>
> It seems you haven't installed the postgis database extras into your postgres 
> database. It depends on your OS how you have to do that.
>
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org             http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
> --
> 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: new user having trouble connecting django to postgres with psycopg2

2011-01-08 Thread Jeff Tchang
Can you try logging into the database and running:

SELECT * FROM pg_timezone_names;

Maybe try picking something from that list?

-Jeff

On Sat, Jan 8, 2011 at 8:19 PM, Mark Brazil  wrote:
> Same error
>
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
>     execute_manager(settings)
>   File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py",
> line 438, in execute_manager
>     utility.execute()
>   File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py",
> line 379, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
> 191, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
> 220, in execute
>     output = self.handle(*args, **options)
>   File "/usr/lib/pymodules/python2.6/django/core/management/base.py", line
> 351, in handle
>     return self.handle_noargs(**options)
>   File
> "/usr/lib/pymodules/python2.6/django/core/management/commands/syncdb.py",
> line 52, in handle_noargs
>     cursor = connection.cursor()
>   File "/usr/lib/pymodules/python2.6/django/db/backends/__init__.py", line
> 75, in cursor
>     cursor = self._cursor()
>   File
> "/usr/lib/pymodules/python2.6/django/db/backends/postgresql_psycopg2/base.py",
> line 144, in _cursor
>     cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
> psycopg2.DataError: unrecognized time zone name: "Australia/NSW"
>
> or if its set to Sydney
> :
> :
> :
> psycopg2.DataError: unrecognized time zone name: "Australia/Sydney"
>
>
>
>
> On 07/01/11 17:43, Subhranath Chunder wrote:
>
> I guess you'll have to set it to 'Australia/ACT Australia/Canberra
> Australia/NSW Australia/Sydney' in your settings.py instead.
> Thanks,
> Subhranath Chunder.
>
> On Fri, Jan 7, 2011 at 6:22 AM, Mark Brazil  wrote:
>>
>> hi,
>>
>> I've been trying to find the answer to this for a bit, but haven't
>> found anything suitable.
>>
>> I have postgresql 9.01, django 1.2.3 psycopg2 on ubuntu10.10
>>
>> When I try to use syncdb i get an error as follows
>>
>> "psycopg2.DataError: unrecognized time zone name"
>>
>> I currently have my settings.py set to "Australia/Sydney".
>>
>> I logged into postgres and set the TZ variable to AEST and started the
>> database.
>>
>> But still get this.
>>
>> I'm guessing it is something simple, but cannot find the answer.
>>
>> Any ideas would be great,
>> Thanks,
>> Mark.
>>
>> --
>> 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.
>>
>
> --
> 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.
>
> --
> 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.
>

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