Search Results

Search found 2 results on 1 pages for 'birdman'.

Page 1/1 | 1 

  • Django MultiWidget Phone Number Field

    - by Birdman
    I want to create a field for phone number input that has 2 text fields (size 3, 3, and 4 respectively) with the common "(" ")" "-" delimiters. Below is my code for the field and the widget, I'm getting the following error when trying to iterate the fields in my form during initial rendering (it happens when the for loop gets to my phone number field): Caught an exception while rendering: 'NoneType' object is unsubscriptable class PhoneNumberWidget(forms.MultiWidget): def __init__(self,attrs=None): wigs = (forms.TextInput(attrs={'size':'3','maxlength':'3'}),\ forms.TextInput(attrs={'size':'3','maxlength':'3'}),\ forms.TextInput(attrs={'size':'4','maxlength':'4'})) super(PhoneNumberWidget, self).__init__(wigs, attrs) def decompress(self, value): return value or None def format_output(self, rendered_widgets): return '('+rendered_widgets[0]+')'+rendered_widgets[1]+'-'+rendered_widgets[2] class PhoneNumberField(forms.MultiValueField): widget = PhoneNumberWidget def __init__(self, *args, **kwargs): fields=(forms.CharField(max_length=3), forms.CharField(max_length=3), forms.CharField(max_length=4)) super(PhoneNumberField, self).__init__(fields, *args, **kwargs) def compress(self, data_list): if data_list[0] in fields.EMPTY_VALUES or data_list[1] in fields.EMPTY_VALUES or data_list[2] in fields.EMPTY_VALUES: raise fields.ValidateError(u'Enter valid phone number') return data_list[0]+data_list[1]+data_list[2] class AdvertiserSumbissionForm(ModelForm): business_phone_number = PhoneNumberField(required=True)

    Read the article

  • Rails has_and_belongs_to_many join across 3 tables

    - by Birdman
    I have a three models: listing, category, and site. There is a many to many relationship between listing and site and there is a many to many relationship between listing and category. A listing thus belongs to one or more sites and one or more categories (a listing can appear on multiple sites and multiple categories). Given a site id and a category id, I want a set of all the listings. I understand how to get the listings from a site id (listings = site.listings) and how to get the listings from a category id (listings = category.listings), but how do I get the triple join of the set of listings from both a site id and category id? The sql would look something like (sit_id and cat_id are input): select l.name from listings l, categories_listings cl, listings_sites, ls where cl.category_id = cat_id and ls.site_id = sit_id and cl.listing_id = l.id and ls.listing_id = l.id Thanks in advance

    Read the article

1