Re: Need help with a form instance

2011-05-19 Thread Oleg Lomaka
That is weird. I don't see serious errors in your view code. I would look at request.POST. May be you forgot to include formset.management_form into your template or something like this... ps: if you use django 1.3, there is a django.shortcuts.render method that is looks nicer then render_to_respo

Re: Need help with a form instance

2011-05-18 Thread Oleg Lomaka
You need ModelFormSet. By default, it creates forms for all models from given queryset. On Wed, May 18, 2011 at 12:20 PM, piker wrote: > Ok, I've managed to create a ModelForm instance that enables me to > input total

Re: Django Admin site and password field

2011-05-12 Thread Oleg Lomaka
Sorry, it's unclear you use django's auth.User model or you have custom model for your users? If you have your custom model, then show an admin.py file from your app directory. On Thu, May 12, 2011 at 7:58 AM, Gabe wrote: > I am using built-in Django admin. In my models.py file password field >

Re: CharField with choices gets no ... choices

2011-05-12 Thread Oleg Lomaka
You don't need to override choices for Model, because it is global to validate "what values accepted to store into database". It's not depends on current request scope or session. If you need to provide user with subset of choices to choose from dynamically, then you should use a Form for this. c

Re: class based views

2011-05-12 Thread Oleg Lomaka
http://docs.djangoproject.com/en/1.3/topics/generic-views-migration/ On Thu, May 12, 2011 at 9:56 AM, km wrote: > I do not find any help page on migrating existing function based views > (defined in views.py of django app) to class based views in django.1.3 > pointers and help appreciated. > >

Re: error on django admin

2011-05-09 Thread Oleg Lomaka
Try to add __unicode__ method to your SmartBuy model that returns string. On Mon, May 9, 2011 at 10:32 AM, chhots wrote: > class Like(models.Model): > smartbuy = models.ForeignKey(SmartBuy) > User = models.ForeignKey(User) > def __unicode__(self): > return self.smartbuy or “Smartbuy #%d” % self.

Re: Format a python date

2011-05-09 Thread Oleg Lomaka
You can format your python date in template using datefilter. Also your default date format depends on your current locale. And you can change your date format in settings.py by setting DATE_FORMAT

Re: Encrpting urls to hide PKs

2011-05-09 Thread Oleg Lomaka
Take a look at django-registration app. With slight modification it should satisfy your requirements. For URL encryption, you can generate some sort of UUID and save in your database that such UUID corresponds to given profile PK. django-registration uses such urls for email confirmation. On Mon,

Re: ajax cart

2011-05-09 Thread Oleg Lomaka
you your answer object is 'data', for example, then data[0].id data[0].quant On Mon, May 9, 2011 at 1:56 PM, Паша Тявин wrote: > Hello. I'm newbie and trying to make a simple shopping cart using anonymous > session under ajax control. > I have a special url "/update_cart/" for only post request

Re: Instantiate a model using a string (or a dict)??

2011-05-08 Thread Oleg Lomaka
To extend Shawn's answer on your example :) params = {'username': 'admin', 'email': 'x...@xyz.com', 'password': 'xyz123'} # then new_user = User(**params) new_user.save() # or User.objects.create(**params) On Sun, May 8, 2011 at 1:44 PM, Eiji Kobayashi wrote: > Hi! > > Sorry. Another question, p

Re: book count per author for filtered book list

2011-05-08 Thread Oleg Lomaka
I would do this via intermediate model, class Author(models.Model): name = models.CharField(max_length=250) class Book(models.Model): title = models.CharField(max_length=250) author = models.ManyToManyField(Author, through="BookAuthor") class BookAuthor(models.Model): author = mode

Re: Using fields from multiple models (connected by foreign key) in the ModelAdmin

2011-05-08 Thread Oleg Lomaka
You have started from the beginning. Take a look at my very first reply in this thread. Remove 'areacode' and 'number' fields from your MemberAdmin. Let them be available from PhoneInline and AddressInline. You will be see them on the same admin page, just in other visual block where inline forms d

Re: Using fields from multiple models (connected by foreign key) in the ModelAdmin

2011-05-07 Thread Oleg Lomaka
', 'last_name', 'all_phones') On Sat, May 7, 2011 at 11:59 PM, Eiji Kobayashi wrote: > This doesn't do anything. I still get the same error. > > I'd like to be able to access the fields from the Phone and Address > model from > the MemberAd

Re: Froms new line in forms.py

2011-05-07 Thread Oleg Lomaka
Then you incorrectly use mark_safe function. Again, here is a form example: from django.utils.safestring import mark_safe class MyModelForm(forms.ModelForm): class Meta: model = MyModel def clean_myfield(self): raise forms.ValidationError(mark_safe("Errorhere")) This wo

Re: Froms new line in forms.py

2011-05-07 Thread Oleg Lomaka
You didn't answer first question. What do you mean by "output screen". You see those "" in console by printing the string, or you see it in the browser? On Sat, May 7, 2011 at 5:09 PM, GKR wrote: > Yes It gave the output displaying within the strings. > > -- > You received this message because

Re: Using fields from multiple models (connected by foreign key) in the ModelAdmin

2011-05-07 Thread Oleg Lomaka
Move fields from ModelAdmin to appropriate InlineModelAdmin #admin.py from models import Member, Address, Phone class PhoneInline(admin.StackedInline): model = Phone can_delete = True extra = 0 fields = ('areacode', 'number') class AddressInline(admin.StackedInline): model =

Re: Froms new line in forms.py

2011-05-07 Thread Oleg Lomaka
Do you mean an internet browser by "output screen"? Did you try to mark string as safe by calling mark_safe as I suggested? On Sat, May 7, 2011 at 9:37 AM, GKR wrote: > actually i wanted the output as > > ..already exists. > [DEMO_ > > not > > .

Re: Froms new line in forms.py

2011-05-06 Thread Oleg Lomaka
use mark_safearound your html string if you are sure your variables aren't contains html tags On Fri, May 6, 2011 at 4:09 PM, GKR wrote: > > raise forms.ValidationError("Item Code [" + fieldrec.barcode_id

Re: not able to use editable=True or false in forms.CharField()

2011-05-06 Thread Oleg Lomaka
I'm not sure you need to output a static value that user can't modify in a form field, but if you still need it... some_field = forms.CharField(widget=forms.TextInput(attrs={'readonly': True})) or if you need hidden value some_field = forms.CharField(widget=forms.HiddenInput) On Fri, May 6, 201

Re: CSS linking error

2011-05-03 Thread Oleg Lomaka
It looks you have unnecessary 'static' part in your template. MEDIA_ROOT already contains 'static', so template should looks like this: On Tue, May 3, 2011 at 12:21 PM, Pascal Moutia wrote: > Hi there Django-users > > I'm suppose to link CSS to my base.html but i can't get it worked :s there >

Re: fetching data from intermediate many-to-many table

2011-05-01 Thread Oleg Lomaka
Hm... Again I think I have answered this question already. Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0) These are books, that doesn't belong to any sequence. And with one query (though quite heavy query). 2011/5/1 А. Р. <4d876...@gmail.com> > > That's right. But if we hav

Re: fetching data from intermediate many-to-many table

2011-05-01 Thread Oleg Lomaka
We don't need the first query for fetching books. All data about book available from BookSequence too. And all filters you apply to books, you can apply to BookSequence via book__ filter. Again, from my first example, and using just one query bs = BookSequence.objects.filter(book__title__startswit

Re: fetching data from intermediate many-to-many table

2011-05-01 Thread Oleg Lomaka
ist), then code snippet may looks something like this: Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0) May be if you read docs on ManyToMany relations, you'll find more nicer solution. 2011/5/1 А.Р. <4d876...@gmail.com> > 2011/5/

Re: fetching data from intermediate many-to-many table

2011-05-01 Thread Oleg Lomaka
bs = BookSequence.objects.filter(book__pk=1).select_related() for s in bs: print s.sequence.name, s.number_in_sequence On Sun, May 1, 2011 at 1:30 PM, Alex <4d876...@gmail.com> wrote: > Hello! > Assume we have the following models: > > > class Book(models.Model): >title = models.CharFi

Re: Can any one help me with this error "Page not found (404)" ?

2011-04-27 Thread Oleg Lomaka
Go on read 3rd part of tutorial about urls.py configuration http://docs.djangoproject.com/en/dev/intro/tutorial03/ On Wed, Apr 27, 2011 at 8:13 AM, Maaz Muqri wrote: > Page not found (404) > Request Method: GET > Request URL:http://127.0.0.1:8000/ > Using the URLconf defined in mysite.urls,

Re: Hyperlinks in Messages

2011-04-27 Thread Oleg Lomaka
Just use appropriate filter for your raw message. For example to make all urls clickable in you message, you can apply urlizefilter {% for message in messages %} {{ message*|urlize* }} {% endfor %} Or use safe

Re: Django view in admin index.

2011-04-26 Thread Oleg Lomaka
Not clearly understand what do you need. If you want to modify Admin index page to add your action links or widgets, take a look at django-grappelli or django-admin-tools. If you want to add custom view for your models, then read this http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django

Re: How do I decode a string that it is received by a filter ???

2011-04-26 Thread Oleg Lomaka
?? > I thought this would be very easy to solve. > > I'd thanks any help. > Regards > Ariel > > > On Mon, Apr 25, 2011 at 6:21 PM, Oleg Lomaka wrote: > >> Not sure if it helps in your case, but try to start django in UTF-8 >> locale. For example, >> &

Re: How do I decode a string that it is received by a filter ???

2011-04-25 Thread Oleg Lomaka
Not sure if it helps in your case, but try to start django in UTF-8 locale. For example, LANG=en_US.UTF-8 ./manage.py runserver On Mon, Apr 25, 2011 at 6:23 PM, Ariel wrote: > I have the following problem, I have made a template filter that process a > string, but when the string that is passed

Re: Django ORM question about lookups that span relationships

2011-04-21 Thread Oleg Lomaka
Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), entry__headline__contains='Easter ').latest('pub_date') Or Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), entry__headline__contains='Easter ').order_by('-pub_date')[0] On Th

Re: Why Django Model Filter Returns Model Object Instance Instead of QuerySet?

2011-04-21 Thread Oleg Lomaka
On Fri, Apr 22, 2011 at 1:20 AM, octopusgrabbus wrote: > Here is the pertinent code: > > def reconcile_inv(request): >errors = [] >cs_list = [] >return_dc = {} > cs_hold_rec_count = 0 > try: > cs_hold_rec_count = CsInvHold.objects.count() >qs = CsInvHold.objects.f

Re: filtering drop downs according to logged in user

2011-04-21 Thread Oleg Lomaka
As an option, you can pass a request.user to form's __init__ method from your view. Example: class YourForm(forms.ModelForm): def __init__(self, user, *args, **kwargs): self.user = user super(YourForm, self).__init__(*args, **kwargs) # here you can modify any self.field

Re: object with version

2011-04-21 Thread Oleg Lomaka
Take a look at django-reversion On Thu, Apr 21, 2011 at 5:43 PM, Brian Craft wrote: > I need to create objects with version tracking, a bit like wiki > content. Anyone done this in django? > > I could create a model with a content field and a version field. But > I'm not sure how to query (for ex

Re: queries gone wild

2011-04-20 Thread Oleg Lomaka
Looks like you store dates as strings in sqlite and as dates in mysql. Try this queryset: Duchung.objeccts.filter(Mitarbeiter=request.user.id, Datum__year=str(tag).split('-')[0]) On Wed, Apr 20, 2011 at 11:51 AM, Szabo, Patrick (LNG-VIE) < patrick.sz...@lexisnexis.at> wrote: > > > For developeme

Re: Bug with ModelForm ?

2011-04-20 Thread Oleg Lomaka
When rendering your form in template, fields enumerating from fieldsets variable, not from fields. Sure you can redefine fieldsets in your AdminForm, but then validations will fail as original form class doesn't have such field. One workaround I can propose is to define this field in form definitio

Re: already logged in users

2011-04-19 Thread Oleg Lomaka
{% if user.is_authenticated %} Hello, what are you doing here? {% else %} Show login/registration form here {% endif %} Also I think doing it in templates is not right. It's job for decorators. On Tue, Apr 19, 2011 at 7:46 PM, Luterien wrote: > Hello. I'm working on a django project and now

Re: custom form field validation

2010-07-15 Thread Oleg Lomaka
http://docs.djangoproject.com/en/1.2/ref/forms/fields/#required usu = forms.CharField(required=False, ...) On Jul 15, 2010, at 5:25 PM, refreegrata wrote: > Hello list. I'm a newie in django with many questions. I want to do > something like this: > --

Re: How can view tweak response object to go to a specific *anchor* on the template?

2010-07-15 Thread Oleg Lomaka
Opps, Daniel is right, #anchor element isn't contains in URL, so the only way is javascript. On Jul 15, 2010, at 11:57 AM, Oleg Lomaka wrote: > I see two ways to implement this. > > First without javascript. You cat check URL of HttpRequest and if it is > without #anchor e

Re: How can view tweak response object to go to a specific *anchor* on the template?

2010-07-15 Thread Oleg Lomaka
I see two ways to implement this. First without javascript. You cat check URL of HttpRequest and if it is without #anchor element, then send redirect to the same URL with #anchor. Second using javascript. For example in jquery you can include something like this in your head tag: ... ht

Re: 'django.contrib.comments', Error: No module named comments. Can someone explain why?

2010-07-12 Thread Oleg Lomaka
You already have correct 'django.contrib.comments' in INSTALLED_APPS. Why did you add another 'comments' as last element? On Jul 12, 2010, at 4:14 PM, justin jools wrote: > I've set up basic blog with, all running fine but when I runserver I > get Error: No module named comments. I've checked th

Re: Redirection to login screen goes to Apache root in non-root mod_wsgi based Django app

2010-07-06 Thread Oleg Lomaka
Exactly for your case, you may set LOGIN_URL point to '/myapp/accounts/login/', but 'next' parameter still left inaccurate. http://docs.djangoproject.com/en/dev/ref/settings/#login-url For more general case, to make working not only auth urls, look at those snippets: - http://code.google.com/p/m

Re: Looking for unavailable table?

2010-06-25 Thread Oleg Lomaka
omething like "directory", but I briefly searched online and couldn't tell. > > On Fri, Jun 25, 2010 at 5:35 PM, Oleg Lomaka wrote: > > Did you add your application to INSTALLED_APPS before running syncdb? > > On Jun 26, 2010, at 12:09 AM, Jonathan Hay

Re: Looking for unavailable table?

2010-06-25 Thread Oleg Lomaka
Did you add your application to INSTALLED_APPS before running syncdb? On Jun 26, 2010, at 12:09 AM, Jonathan Hayward wrote: > P.S. Renaming the (SQLite) database file and running syncdb again produces > (basically) the same behavior. I had to do some initialization things again, > but outside

Re: ModelChoiceField

2010-06-24 Thread Oleg Lomaka
On 6/25/10 8:25 AM, Tran Cao Thai wrote: is there any way to use the ModelChoiceField without any value in it? I tried to set query = None but it gave an error while rendering the html page Use EmptyQuerySet. field = ModelChoiceField(queryset=YouMode.objects.none()) http://docs.djangoproject