Re: Additional fields in the many-to-may table?
I was thinking that, but wanted to make sure Thanks for helping a n00b, and creating a great framework! Corey On May 25, 2006, at 10:50 AM, Adrian Holovaty wrote: > > On 5/25/06, Corey <[EMAIL PROTECTED]> wrote: >> Is there a way to add additional fields to the many-to many table, or >> is there a better way to accomplish what I want. >> >> I have a Groups table and an Attributes table with a many-to-many >> relationship. >> >> I want to be able to specify the viewing order of the attribute >> and if >> the attribute is required on a per-group basis. >> >> I would typically put it in a schema like: >> >> Group GroupAttributeAttribute >> - --- - >> id group_id id >> Name attribute_id Name >>viewing_order >>required > > Hey Corey, > > Welcome to the Django community. :) > > The best way to solve your particular problem would be to create a > GroupAttribute model rather than using a ManyToManyField in either > Group or Attribute. That way, you can give the GroupAttribute model as > many extra fields as you want. > > Adrian > > -- > Adrian Holovaty > holovaty.com | djangoproject.com > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~--~~~~--~~--~--~---
Re: Proposal: Search Manipulator
Here is my code for the AutomaticSearchManipulator: from django.db.models.manipulators import * from django.db.models.query import Q class AutomaticSearchManipulator (AutomaticManipulator): """ A generic manipulator for searching. It does all the work for "query by example" queries. Typical view usage: def address_search(request): Address.add_to_class('SearchManipulator', AutomaticSearchManipulator) manipulator = Address.SearchManipulator() if request.GET: new_data = request.GET.copy() manipulator.do_html2python(new_data) query_set = manipulator.search(new_data) return render_to_response('address_list.html', {'object_list': query_set}) else: errors = new_data = {} form = forms.FormWrapper(manipulator, new_data, errors) return render_to_response('address_search.html', {'form': form}) """ change = False SEARCH_TYPES = { 'iexact': '=', 'exclude': '≠', 'istartswith': 'starts with', 'iendswith': 'ends with', 'icontains': 'contains', 'gt': '>', 'gte': '>=', 'lt': '<', 'lte': '<=', 'in': 'one of', 'range': 'range of', } def search_types(self): """ Generate the search type drop-down widget. Currently doesn't work, need to figure out how to adjust the name of the widget to correspond with the field. Meant to be used in forms (added as an extra context) to allow more flexible searching. """ output = ['' % ()] str_data = str(data) # normalize to string for value, display_name in self.SEARCH_TYPES: selected_html = '' if str(value) == str_data: selected_html = ' selected="selected"' output.append('%s' % \ (escape(value), selected_html, escape (display_name))) output.append(' ') return '\n'.join(output) def save(self, new_data): """ Does nothing. Doesn't make sense to have a save method. Raise NotImplementedError """ raise NotImplementedError def search(self, new_data, default_search='iexact'): """ Search for the object or objects specified by new_data. """ where_clause = {} posted_values = new_data.lists() for k, v in posted_values: if len(v) > 1: where_clause['%s__in' % k] = v else: if v[0]: where_clause['%s__%s' % (k, default_search)] = v[0] if where_clause: q = Q(**where_clause) return self.manager.filter(q) else: return self.manager.all() On Aug 20, 2006, at 2:51 PM, Corey wrote: > > I had a need to provide a "Search by example" form, and I thought that > a new type of manipulator similar to an AddManipulator and > ChangeManipulator. > > I've started the code, and would be happy to submit when I'm done if > you guys/glas think it Django-ish enough. > > The idea is that a view to handle searching could look like: > > def address_search(request): > manipulator = Address.SearchManipulator() > if request.GET: > new_data = request.GET.copy() > manipulator.do_html2python(new_data) > query_dict = manipulator.search(new_data) > return render_to_response('address_list.html', {'query_dict': > query_dict}) > else: > errors = new_data = {} > > form = forms.FormWrapper(manipulator, new_data, errors) > return render_to_response('address_search.html', {'form': form}) > > Thanks, > > Corey > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~--~~~~--~~--~--~---
Re: db_index not creating indexes with syncdb
try ./manage.py install, it executes sqlall Corey On Aug 23, 2006, at 2:42 PM, [EMAIL PROTECTED] wrote: > > I've got the following: > > class Page(models.Model): > name = models.CharField(maxlength=64, db_index=True, > unique=True) > description = models.TextField(blank=True) > > class Text(models.Model): > page = models.ForeignKey(Page, db_index=True, > edit_inline=models.STACKED) > content = models.TextField(core=True) > > When I run "./manage.py syncdb" it creates the tables and everything > works ok, but if I look in MySQL at the table description, the index > isn't listed: > > mysql> desc page_text; > +--+--+--+-+- > ++ > | Field| Type | Null | Key | Default | > Extra | > +--+--+--+-+- > ++ > | id | int(11) | | PRI | NULL| > auto_increment | > | page_id | int(11) | | | 0 > || > | content | longtext | | | > || > > But if I view the "./manage sqlall page" it lists the CREATE INDEX > statements... > > CREATE TABLE `page_text` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `page_id` integer NOT NULL, > `content` longtext NOT NULL, > ); > ALTER TABLE `page_text` ADD CONSTRAINT page_id_refs_id_7038ecc2 > FOREIGN > KEY (`page_id`) REFERENCES `page_page` (`id`); > CREATE INDEX page_text_page_id ON `page_text` (`page_id`); > > And if I copy and paste those statements it works ok too. But I'd > expect this to happen via syncdb. > > There is a bug so I didn't create a new one but it mentions sqlreset > even though this bug exists for syncdb... > http://code.djangoproject.com/ticket/1828 > > Are there different places the calls are made for syncdb vs. > sqlall? I > can dig into the code to see what the differences might be. > > Thanks, > Rob > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~--~~~~--~~--~--~---