Index: django/core/meta.py
===================================================================
--- django/core/meta.py	(revision 338)
+++ django/core/meta.py	(working copy)
@@ -393,11 +393,58 @@
 
 class ModelBase(type):
     "Metaclass for all models"
+    
+    # We need to keep track of Fields which are initiated inside of the class body, but
+    # not assined to an attribute.  (These could be ForeignKeys, ManyToManyFields, or
+    # OneToOneFields.)
+    _defined_fields_bank = {}
+    
     def __new__(cls, name, bases, attrs):
         # If this isn't a subclass of Model, don't do anything special.
         if not bases:
             return type.__new__(cls, name, bases, attrs)
 
+        # We must refactor the attributes around a little.  All Field class instances will be given
+        # names (as needed) and moved to the fields list.  All attributes of the Meta class will 
+        # be moved into the main class attrs.
+
+        attrs["fields"] = attrs.has_key("fields") and list(attrs["fields"]) or []
+
+        def handle_field(obj, name):
+            if isinstance(obj, Field):  #Check if this is a field
+                if isinstance(obj,(ForeignKey, ManyToManyField, OneToOneField)):
+                    obj.rel.name = name
+                    # We need to delete this Field from the dict, as it was assigned
+                    # to an attribute.  (We don't want to add it again later.)
+                    del ModelBase._defined_fields_bank[id(obj)]
+                else:
+                    obj.set_name(name)
+                attrs["fields"].append(obj)
+                return True
+            else:
+                return False
+
+        # loop through the attributes, and take out the fields.
+        for key in attrs.keys()[:]:
+            if handle_field(attrs[key], key):
+                del attrs[key]  # If the attr was added to fields, we want to delete it.
+
+        # Add all of the relationship fields that were not assigned to an attribute.
+        attrs["fields"].extend( ModelBase._defined_fields_bank.values() )
+        ModelBase._defined_fields_bank = {}
+
+        if attrs.has_key("Meta"):
+            for name in dir(attrs["Meta"]):
+                if name.startswith("__"): continue
+                if name in ("fields",):
+                    attrs[name].extend( getattr(attrs["Meta"],name) )
+                else:
+                    attrs[name] = getattr(attrs["Meta"],name)
+            del attrs["Meta"]
+
+        # Sort the fields, so that they appear in the correct order.
+        attrs["fields"].sort(lambda x,y: x.creation_counter - y.creation_counter)
+
         # If this model is a subclass of another Model, create an Options
         # object by first copying the base class's _meta and then updating it
         # with the overrides from this class.
@@ -1572,14 +1619,19 @@
     # database level.
     empty_strings_allowed = True
 
-    def __init__(self, name, verbose_name=None, primary_key=False,
+    # Will be increased each time a Field object is instanced.  Used to
+    # retain the order of fields.
+    creation_counter = 0
+
+    def __init__(self, name=None, verbose_name=None, primary_key=False,
         maxlength=None, unique=False, blank=False, null=False, db_index=None,
         core=False, rel=None, default=NOT_PROVIDED, editable=True,
         prepopulate_from=None, unique_for_date=None, unique_for_month=None,
         unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
         help_text=''):
         self.name = name
-        self.verbose_name = verbose_name or name.replace('_', ' ')
+        self.original_verbose_name = verbose_name
+        self.verbose_name = verbose_name or name and name.replace('_', ' ')
         self.primary_key = primary_key
         self.maxlength, self.unique = maxlength, unique
         self.blank, self.null = blank, null
@@ -1604,6 +1656,24 @@
         else:
             self.db_index = db_index
 
+        # Increase the creation counter, and save our local copy.
+        self.creation_counter = Field.creation_counter
+        Field.creation_counter += 1
+
+    def set_name(self, name ):
+        """
+        Sets the name, and generates the verbose_name from it if needed.
+        This function is here for when the name needs to be set later, (such as if it needs to be obtained from
+        a the attribute name that stores the Field instance.)
+        """
+        if not self.original_verbose_name:
+            # If the verbose name was originally not specified, we will assume that 
+            # the user intends for the first argument passed to __init__ to be the verbose_name.
+            self.verbose_name = self.name
+            
+        self.name = name
+        self.verbose_name = self.verbose_name or name and name.replace('_', ' ')
+            
     def pre_save(self, obj, value, add):
         """
         Hook for altering the object obj based on the value of this field and
@@ -1789,7 +1859,7 @@
 
 class DateField(Field):
     empty_strings_allowed = False
-    def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):
+    def __init__(self, name=None, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):
         self.auto_now, self.auto_now_add = auto_now, auto_now_add
         if auto_now or auto_now_add:
             kwargs['editable'] = False
@@ -1845,7 +1915,7 @@
         return [formfields.EmailField]
 
 class FileField(Field):
-    def __init__(self, name, verbose_name=None, upload_to='', **kwargs):
+    def __init__(self, name=None, verbose_name=None, upload_to='', **kwargs):
         self.upload_to = upload_to
         Field.__init__(self, name, verbose_name, **kwargs)
 
@@ -1910,7 +1980,7 @@
 
 class FloatField(Field):
     empty_strings_allowed = False
-    def __init__(self, name, verbose_name=None, max_digits=None, decimal_places=None, **kwargs):
+    def __init__(self, name=None, verbose_name=None, max_digits=None, decimal_places=None, **kwargs):
         self.max_digits, self.decimal_places = max_digits, decimal_places
         Field.__init__(self, name, verbose_name, **kwargs)
 
@@ -1992,7 +2062,7 @@
 
 class TimeField(Field):
     empty_strings_allowed = False
-    def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):
+    def __init__(self, name=None, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs):
         self.auto_now, self.auto_now_add  = auto_now, auto_now_add
         if auto_now or auto_now_add:
             kwargs['editable'] = False
@@ -2019,7 +2089,7 @@
         return [formfields.TimeField]
 
 class URLField(Field):
-    def __init__(self, name, verbose_name=None, verify_exists=True, **kwargs):
+    def __init__(self, name=None, verbose_name=None, verify_exists=True, **kwargs):
         if verify_exists:
             kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
         Field.__init__(self, name, verbose_name, **kwargs)
@@ -2032,7 +2102,7 @@
         return [formfields.USStateField]
 
 class XMLField(Field):
-    def __init__(self, name, verbose_name=None, schema_path=None, **kwargs):
+    def __init__(self, name=None, verbose_name=None, schema_path=None, **kwargs):
         self.schema_path = schema_path
         Field.__init__(self, name, verbose_name, **kwargs)
 
@@ -2065,6 +2135,7 @@
             lookup_overrides=kwargs.pop('lookup_overrides', None),
             raw_id_admin=kwargs.pop('raw_id_admin', False))
         Field.__init__(self, **kwargs)
+        ModelBase._defined_fields_bank[id(self)]=self
 
     def get_manipulator_field_objs(self):
         return [formfields.IntegerField]
@@ -2080,6 +2151,7 @@
             filter_interface=kwargs.pop('filter_interface', None),
             limit_choices_to=kwargs.pop('limit_choices_to', None))
         Field.__init__(self, **kwargs)
+        ModelBase._defined_fields_bank[id(self)]=self
 
     def get_manipulator_field_objs(self):
         choices = self.get_choices(include_blank=False)
@@ -2105,6 +2177,7 @@
             raw_id_admin=kwargs.pop('raw_id_admin', False))
         kwargs['primary_key'] = True
         IntegerField.__init__(self, **kwargs)
+        ModelBase._defined_fields_bank[id(self)]=self
 
 ####################
 # RELATIONSHIPS    #
