Ticket #1335: docs_db-api.txt.diff
File docs_db-api.txt.diff, 7.5 KB (added by , 19 years ago) |
---|
-
django/models/auth.py
2 2 from django.models import core 3 3 from django.utils.translation import gettext_lazy as _ 4 4 5 5 6 class Permission(meta.Model): 6 7 name = meta.CharField(_('name'), maxlength=50) 7 8 package = meta.ForeignKey(core.Package, db_column='package') … … 29 30 def __repr__(self): 30 31 return self.name 31 32 32 class User(meta.Model): 33 34 class UserUv2Constants(object): 35 """Constants for the UserUv2 class. 36 """ 37 TYPE_DISTRIBUTOR = "D" 38 TYPE_ADMINISTRATOR = "A" 39 TYPE_PROCESSOR = "P" 40 41 42 class UserUv2(UserUv2Constants): 43 """Base class for adding our custom fields to the django user model. 44 This model is inherited by django.models.auth.User 45 """ 46 def get_payee(self): 47 """Returns this user's Payee object. 48 Returns None if this user is not associated with a payee. 49 """ 50 try: 51 from django.models.uv2 import payees 52 return payees.get_object(u__id__exact=self.id) 53 except: 54 return None 55 56 def get_person(self): 57 """Returns this user's Person object. 58 Returns None if this user is not associated with a person. 59 """ 60 try: 61 from django.models.uv2 import persons 62 return persons.get_object(u__id__exact=self.id) 63 except: 64 return None 65 66 def get_address(self): 67 """Returns this user's Address object. 68 Returns None if this user is not associated with an address. 69 """ 70 try: 71 from django.models.uv2 import addresses 72 return addresses.get_object(u__id__exact=self.id) 73 except: 74 return None 75 76 def get_type(self): 77 """Returns the type of user this is. 78 Looks up the type in our persons table. 79 Returns None if this user is not associated with a person. 80 """ 81 try: 82 p = self.get_person() 83 return p.type 84 except: 85 return None 86 87 def is_distributor(self): 88 """Returns true if this user is a uv2 Distributor. 89 Returns None if this user is not associated with a person. 90 """ 91 try: 92 return self.get_type() == self.TYPE_DISTRIBUTOR 93 except: 94 return None 95 96 def is_processor(self): 97 """Returns true if this user is a uv2 Processor. 98 Returns None if this user is not associated with a person. 99 """ 100 try: 101 return self.get_type() == self.TYPE_PROCESSOR 102 except: 103 return None 104 105 106 def is_administrator(self): 107 """Returns true if this user is a uv2 Administrator. 108 Returns None if this user is not associated with a person. 109 """ 110 try: 111 return self.get_type() == self.TYPE_ADMINISTRATOR 112 except: 113 return None 114 115 116 class META: 117 no_table = True 118 119 120 class User(meta.Model, UserUv2): 33 121 username = meta.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric]) 34 122 first_name = meta.CharField(_('first name'), maxlength=30, blank=True) 35 123 last_name = meta.CharField(_('last name'), maxlength=30, blank=True) … … 66 154 67 155 def __repr__(self): 68 156 return self.username 157 #return "User is a distributor: %s" % self.is_distributor() 69 158 70 159 def get_absolute_url(self): 71 160 return "/users/%s/" % self.username -
django/core/meta/__init__.py
625 625 # attribute order. 626 626 fields.sort(lambda x, y: x.creation_counter - y.creation_counter) 627 627 628 # Should this class generate database tables (Default is Yes)? 629 # This has the ultimate effect of keeping this class out of the _MODELS 630 # list. 631 create_table = not (meta_attrs.pop('no_table', False)) 632 628 633 # If this model is a subclass of another model, create an Options 629 634 # object by first copying the base class's _meta and then updating it 630 635 # with the overrides from this class. … … 889 894 # contain this list: 890 895 # [<class 'django.models.polls.Poll'>, <class 'django.models.polls.Choice'>] 891 896 # Don't do this if replaces_module is set. 892 app_package.__dict__.setdefault('_MODELS', []).append(new_class) 897 # Exclude models where the user has set 'no_table = True' 898 if create_table: 899 app_package.__dict__.setdefault('_MODELS', []).append(new_class) 893 900 894 901 # Cache the app label. 895 902 opts.app_label = app_label … … 938 945 def __repr__(self): 939 946 return '<%s object>' % self.__class__.__name__ 940 947 948 941 949 ############################################ 942 950 # HELPER FUNCTIONS (CURRIED MODEL METHODS) # 943 951 ############################################ … … 1027 1035 if opts.has_auto_field and not pk_set: 1028 1036 setattr(self, opts.pk.attname, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 1029 1037 db.db.commit() 1038 1039 # Update the auto_now and auto_now_add fields to the values just inserted 1040 # into the database 1041 i = 0 1042 for f in non_pks: 1043 if isinstance(f, DateField): 1044 if f.auto_now or (f.auto_now_add and not record_exists): 1045 setattr(self, f.attname, db_values[i]) 1046 i += 1 1047 1030 1048 # Run any post-save hooks. 1031 1049 if hasattr(self, '_post_save'): 1032 1050 self._post_save() -
django/core/template/loader.py
103 103 context_instance = Context(dictionary) 104 104 return t.render(context_instance) 105 105 106 def render_to_file(template_name, file_path, mode='w', dictionary=None, context_instance=None): 107 """ 108 Loads the given template_name and renders it, with the given dictionary as 109 context, to a file on disk. The template_name may be a string to load a 110 single template using get_template, or it may be a tuple to use 111 select_template to find one of the templates in the list. file_path defines 112 the file that will be written to disk. mode defaults to 'w' which will 113 create the file if it doesn't exist and will overwrite the file if it does 114 exist. 115 """ 116 f = open(file_path, mode) 117 f.write(render_to_string(template_name, dictionary, context_instance)) 118 f.close() 119 106 120 def select_template(template_name_list): 107 121 "Given a list of template names, returns the first that can be loaded." 108 122 for template_name in template_name_list: -
docs/db-api.txt
173 173 in In a given list: ``polls.get_list(id__in=[1, 3, 4])`` returns 174 174 a list of polls whose IDs are either 1, 3 or 4. 175 175 startswith Case-sensitive starts-with: 176 ``polls.get_list(question_ startswith="Would")``. (PostgreSQL176 ``polls.get_list(question__startswith="Would")``. (PostgreSQL 177 177 and MySQL only. SQLite doesn't support case-sensitive LIKE 178 178 statements; ``startswith`` will act like ``istartswith`` for 179 179 SQLite.)