Re: Ordering a django change list page via jQuery?

2009-08-20 Thread krylatij
I think that is not the best solution. As i understand you are ordering only displayed items because of pagination --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

Re: django queryset based on when data created

2009-08-06 Thread krylatij
You can use ordering by primary key (id by default) because it increments by every insert. So newly created rows in db will have greater id than others. In most cases it can be enough. --~--~-~--~~~---~--~~ You received this message because you are subscribed to

Re: Get current user outside a view / without an request object

2009-08-06 Thread krylatij
> ..go back and read the original poster's > message. Having the user in threadlocals doesn't solve any problem, > since he's trying to create a form class based on information in the > request and that only happens at import time, not every time something > in the file is looked at. Yes, my

Re: Get current user outside a view / without an request object

2009-08-06 Thread krylatij
Why do you think so? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to

Re: Get current user outside a view / without an request object

2009-08-06 Thread krylatij
You can also use threadlocals middleware (ask google about it =)) to get current user without request object --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Calculating a date

2009-08-05 Thread krylatij
from datetime import date, timedelta a = date.today() - timedelta(7 * 12) print a 2009-05-13 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Memory error

2009-08-05 Thread krylatij
try http://docs.djangoproject.com/en/dev/ref/settings/#file-upload-max-memory-size --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Multiple data formats for one view

2009-08-05 Thread krylatij
Why not? You can simply specify mimetype in HttpResponse object urls.py (r'^articles.xml/$', my_view_function, {'format': 'xml'}), (r'^articles.html/$', my_view_function, {'format': 'html'}), views.py def my_view_function(request, format='json'): if format == 'xml': mimetype = '.'

Re: Checking POST Variables are set?

2009-08-05 Thread krylatij
You need to ensure that key exists: if request.POST.get('Lived_Out_Uk', '0') == '1': . --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: buildung query with ORM

2009-08-04 Thread krylatij
It's difficult to even imagine such query (possible but very inefficient), i think you need to change your architecture or do this grouping in bussines layer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: Django admin panel how add extra function in form processing?

2009-08-04 Thread krylatij
Why do you need admin here? You can generate it in the save() method of your model. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: standalone script

2009-08-04 Thread krylatij
or there is another way. create custom command for manage.py (http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ #howto-custom-management-commands) it's pretty simple. then write bash script like this: #!/bin/bash export PYTHONPATH=/path/to/django cd /path/to/project python

Re: standalone script

2009-08-04 Thread krylatij
I guess you are using SSH? so before running your script run: export PYTHONPATH=/path/to/django hope this helps --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

Re: buildung query with ORM

2009-08-04 Thread krylatij
You need to use raw sql. (http://docs.djangoproject.com/en/dev/topics/ db/sql/#topics-db-sql) I don't understand what will be if there are more then 2 channels at the same datetime? So i can't provide you solutions sample. --~--~-~--~~~---~--~~ You received this

Re: A custom ordering SQL and Django models

2009-08-04 Thread krylatij
Use extra() method of query set with little hack ;) mymodel.objects.extra(select={'ordering_field': 'IF(STRCMP (bbs_tag.name, 'notice'), '',bbs_tag.name)'}, order_by=['ordering_field']) --~--~-~--~~~---~--~~ You received this message because you are subscribed to

Re: Filtered ManyToMany list in admin?

2009-08-04 Thread krylatij
Yes, it is possible. try this http://code.google.com/p/django-ajax-filtered-fields/ I usually write this stuff by myself, so if this solution does not works for you, i can provide my. --~--~-~--~~~---~--~~ You received this message because you are subscribed to

Re: creating automatically url for additional column in admin view

2009-08-04 Thread krylatij
Look at http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls It will be like this: from django.core import urlresolvers my_url = "%s?tender__id__exact=%s" % ( urlresolvers.reverse('admin:tender_download_changelist'), self.id )

Re: What's wrong with 10 or more objects?

2009-08-04 Thread krylatij
try: url(r'^keyword/modify/(?P\d+)/$', 'klucoveSlovo_update', name = 'keyword-modify'), --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: custom template tags and template loaders

2009-07-29 Thread krylatij
And do you want to avoid 'django.template.loaders.app_directories.load_template_source' ? It will work only when your template will not be found in default template directory So i guess there is no overhead when you use it in production. May be you have DEBUG=True in your development version

Re: custom template tags and template loaders

2009-07-29 Thread krylatij
And what about other custom tags? I actually have no more ideas, what it can be. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Simple Pagination Problem

2009-07-29 Thread krylatij
Read documentation http://www.djangoproject.com/documentation/models/pagination/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: custom template tags and template loaders

2009-07-29 Thread krylatij
I my case custom tags are still working after i removed ''django.template.loaders.app_directories.load_template_source'' from settings. You can see comment in site-packages\django\template\loaders \app_directories.py: """ Wrapper for loading templates from "templates" directories in

Re: custom template tags and template loaders

2009-07-29 Thread krylatij
No, this settings 'django.template.loaders.app_directories.load_template_source' means, that django will look for templates( not tags ) in each(!) application you have in INSTALLED_APPS (if application folder has folder 'templates' ). On Jul 28, 11:23 pm, chefsmart

Re: change query for ModelChoiceField

2009-05-12 Thread krylatij
def __init__(self, *args, **kwargs): super(ShippingMethodForm, self).__init__(*args, **kwargs) if self.fields['country'].initial == 'Canada': filter_kwargs = { 'delivery_time__lte': time_avail_hours, 'abbrev__contains'='SC' } elif: ... else: ..

Re: The SQL "IN" operator

2009-01-22 Thread krylatij
There is a very good solution for tagging http://code.google.com/p/django-tagging/ try this, it will save you a waste of time --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this

Re: FileBrowser and TinyMCE

2009-01-20 Thread krylatij
You are welcome )) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to

Re: FileBrowser and TinyMCE

2009-01-20 Thread krylatij
not magic)) incorrect settings. make sure that all required javascript is avaliable. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: FileBrowser and TinyMCE

2009-01-20 Thread krylatij
Look into your settings again. I've had such problem before. After some magic with settings everything works. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: what to use for search facility

2009-01-18 Thread krylatij
Sphinx Here samples http://softwaremaniacs.org/blog/2007/11/04/sphinx-search-in-cicero/ (but in Russian) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: where are the code that handle image file upload in Django admin page?

2008-12-23 Thread krylatij
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ here is a sample how to handle file upload And have tried: MyForm.save()? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post

Re: How to set the from a ModelChoiceField?

2008-12-22 Thread krylatij
class MyForm(...): def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['myfield'].choices = City.objects.values_list('id', name_field) --~--~-~--~~~---~--~~ You received this message because you are

Session and request.FILES

2008-12-22 Thread krylatij
I'm writing custom session based wizard (data between step is stored in sessions). One of the steps is uploading files (not the last). The problem is that i save models only after last step. So the question is how to deal with files? As i understand there is no way to store files in session

Re: Complex lookups and SelectMultiple widget

2008-12-07 Thread krylatij
> I am working on a search form that has a SelectMultiple widget. What > would be the best way to make a complex lookup with the SelectMultiple > widget? try this: try: district_ids = [int(x) for x in request.GET.getlist('district')] if len(district_ids) == 0: district_ids =

Re: How to save/link/rename thumbnail in model

2008-10-21 Thread krylatij
You can define image upload path at runtime (check manual for ImageField) def get_photo_path(instance, filename): return 'static/upload_to/photos/%s' % instance.name class ProductImage(models.Model): name = models.CharField(max_length=50) file = models.ImageField(upload_to=

Re: syntax for runtime evaluation of Q objects

2008-10-18 Thread krylatij
You can also try this: or_query = Q() if places: or_query = or_query | Q(persplace__icontains=places) if names: or_query = or_query | Q(persname__icontains=names) results = Person.objects.filter(or_query) --~--~-~--~~~---~--~~ You received this

Re: Extending the User model

2008-10-17 Thread krylatij
Take a look at http://code.google.com/p/django-profile/ --~--~-~--~~~---~--~~ 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

Re: How to display image from ImageField in ModelAdmin?

2008-10-17 Thread krylatij
Code above was a bit incorrect. Here better solution: ## widget declaration from django.utils.safestring import mark_safe from django.forms.widgets import FileInput class AdminImageFieldWithThumbWidget(FileInput): def __init__(self, thumb_width=50, thumb_height=50): self.width =

Re: advice on admin site structure

2008-10-10 Thread krylatij
Sorry, it was my mistake about: > content_type = ContentType.objects.get_by_id(p.contenttype_id) Try this: > content_type = ContentType.objects.get_for_id(p.contenttype_id) About overriding save() method see

Re: advice on admin site structure

2008-10-09 Thread krylatij
First of all about ContentTypes: For example in your Page table you have 2 lines. One is PageText, another PageGallery. So you have 2 different ContentTypes. How to determine type of Page: p = Page.objects.get(id='main') #here we get ContentType object for PageText or PageGallery

Re: advice on admin site structure

2008-10-09 Thread krylatij
If you want to have some hierarchy for you pages, look at django-mptt, but with this inheritance type (non abstract) it works not correct (I have added some changes to it to support this) another way i describe below. If you don't need hierarchy, so simple add 'order' field to Page For

Re: advice on admin site structure

2008-10-09 Thread krylatij
You can also inherit you GalleryPage and TextPage from your Page (not Abstract). Add content_type field to your Page. So it's easier to determine page by it's id, when i will write views. After that register in admin only TextPage and GalleryPage. Hope this helps

Re: Why does MySql gives warning? Incorrect string value: '\xE6\x9D\xB1\xE8\xA8\xBC...' for column 'title' at row 1

2008-10-06 Thread krylatij
Set collation to utf-8 I had the same problem with Russian until i change collation for all char field in my DB to utf-8 and default collation for DB --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users"

Re: How to display image from ImageField in ModelAdmin?

2008-10-01 Thread krylatij
I have written some sample. it works for me, hope it will be usefull: from django.contrib.admin.widgets import AdminFileWidget from django.utils.safestring import mark_safe class AdminImageFieldWithThumbWidget(AdminFileWidget): def render(self, name, value, attrs=None): thumb_html =

Re: automatically generated field in admin

2008-10-01 Thread krylatij
Full example here http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIchangetheattributesforawidgetonafieldinmymodel. class MyModelAdmin(admin.ModelAdmin): ... def formfield_for_dbfield(self, db_field, **kwargs): field = super(MyModelAdmin,

Re: Extra select question

2008-10-01 Thread krylatij
Thanx, works perfectly! --~--~-~--~~~---~--~~ 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

Extra select question

2008-09-30 Thread krylatij
I have model with 3 fields - id, name_ru, name_en I want rename 'name_ru' field to 'name' in query i try this: operations = OperationType.objects.values('id').extra(select={'name': 'name_ru'}) but it returns only 'id' what's wrong?? --~--~-~--~~~---~--~~

Re: Admin internationalization

2008-09-30 Thread krylatij
I use same django instalation for several projects, so it will cause other projects works incorrectly. Any way, thank you for advise --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to

Re: Admin internationalization

2008-09-30 Thread krylatij
unfortunately i'm not Moldavian-speaker =(( outsourcing =)) So as i understood the only solution is to write middleware, to change locale dynamically --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users"

Re: How to display image from ImageField in ModelAdmin?

2008-09-29 Thread krylatij
I think you need to write custom widget for ImageField --~--~-~--~~~---~--~~ 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

Admin internationalization

2008-09-29 Thread krylatij
I have Django site in 2 languages - Moldavian(default) and Russian But django-admin is not localized for Moldavian, that's way i want to use Russian in admin. So my settings.py will look like this: LANGUAGE_CODE = 'md' LANGUAGES = ( ('md', (u'Moldavian')), ('ru', (u'English')), ) But

Re: No delete in newforms-admin

2008-09-29 Thread krylatij
Add extra variable to the context in this way: http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowcanIpassextracontextvariablesintomyaddandchangeviews then override your submit_line.html template and put into it something like that: {% if my_show_delete_link %} {% if show_delete_link %}{%

Re: get children of children

2008-09-25 Thread krylatij
You can also try django-mptt, that works great with object hierarchy http://code.google.com/p/django-mptt/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Auto Discover on MediaTemple

2008-09-23 Thread krylatij
make sure that you use Django 1.0 this mechanizm was changed since 0.96 --~--~-~--~~~---~--~~ 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

Re: seeking design advice

2008-09-18 Thread krylatij
So you can add context variable in your tag and check it in template {%if my_tag_js_not_added %} alert(); {% endif %} ... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to

Re: seeking design advice

2008-09-18 Thread krylatij
you can add JS not only inside --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to

Re: Form validation problem for model with ForeignKey having unique=True,blank=True,null=True

2008-09-11 Thread krylatij
You can create only one model with empty 'other' field. If you could create one more, field 'other' will not be unique more. That's why validation fails. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: ManyToMany performance..

2008-09-04 Thread krylatij
sorry, you need story = Story.objects.filter(pk=1).extra(select={'main_section': sub_select }).values('main_section', 'other_field1', 'other_field2' ) [0] because we get here list of dictionaries Good luck! --~--~-~--~~~---~--~~ You received this message

Re: ManyToMany performance..

2008-09-04 Thread krylatij
You can use an extra select to get additional parameter 'main_section' This is for MySQL and it's only sample you need to test it in your DB to make sure, that it works sub_select = """SELECT section_name FROM %(table_section)s as sc, % (table_section_story)s as st

Re: How to display Html in my screen

2008-09-03 Thread krylatij
Use filter "safe" in your template: {{ mymodel.page|safe }} --~--~-~--~~~---~--~~ 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

Re: ManyToMany performance..

2008-09-03 Thread krylatij
I still think you need second query. as i understand from your code get_main_section will return list of Sections in Story? I mean this string: (section_name = self.id_section.all().order_by('order') ) bad: if (len(self.id_section.all()) > 1):#hits DB section_name =

Re: ManyToMany performance..

2008-09-03 Thread krylatij
it seems you need extra select anyway or use .extra(...) to add additional args to db query (http://www.djangoproject.com/documentation/db-api/#extra-select-none- where-none-params-none-tables-none-order-by-none-select-params-none) But i don't understand. Imagine we have Story with 3 Sections

Re: ManyToMany performance..

2008-09-03 Thread krylatij
Solution #1: use select_related() method when you get your Story from db: Story.objects.get(pk=3).select_related() Solution #2: add to your Section class definition method: def __unicode__(self): return self.section_name and change your template to: {{

Re: Accessing meta class info from my views.py

2008-09-03 Thread krylatij
try this: >>get_models(arteak.management.models)[0]._meta.verbose_name_plural() --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: threadlocals: hack or best practice?

2008-09-01 Thread krylatij
I'm still using threadlocals. It's more convenient for me. --~--~-~--~~~---~--~~ 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

Re: limiting choices in admin.ModelAdmin based on request.user

2008-08-25 Thread krylatij
> There is no longer any reason whatsoever to use this in any way in the > admin. It was an ugly, fragile hack before and it's unnecessary now > because ModelAdmin has a get_form() method -- which receives the > HttpRequest object as an argument -- that you can override to tweak > the form on a

Re: limiting choices in admin.ModelAdmin based on request.user

2008-08-25 Thread krylatij
On 24 авг, 23:56, "Patrick J. Anderson" <[EMAIL PROTECTED]> wrote: > How should I limit choices for ForeignKey fields in admin.ModelAdmin > instances based on request.user attributes, since I can't pass a request > object to the forms.ModelForm constructor? You can use ThreadLocals middleware