Skip to content

Commit 73ba469

Browse files
committed
Split model _meta into model_options and _model_meta
1 parent d7d5947 commit 73ba469

File tree

63 files changed

+1356
-1187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1356
-1187
lines changed

plain-admin/plain/admin/views/models.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_title(self) -> str:
5353
if title := super().get_title():
5454
return title
5555

56-
return self.model._meta.model_name.capitalize() + "s"
56+
return self.model.model_options.model_name.capitalize() + "s"
5757

5858
@classmethod
5959
def get_nav_title(cls) -> str:
@@ -63,14 +63,14 @@ def get_nav_title(cls) -> str:
6363
if cls.title:
6464
return cls.title
6565

66-
return cls.model._meta.model_name.capitalize() + "s"
66+
return cls.model.model_options.model_name.capitalize() + "s"
6767

6868
@classmethod
6969
def get_path(cls) -> str:
7070
if path := super().get_path():
7171
return path
7272

73-
return f"{cls.model._meta.model_name}/"
73+
return f"{cls.model.model_options.model_name}/"
7474

7575
def get_template_context(self) -> dict[str, Any]:
7676
context = super().get_template_context()
@@ -167,20 +167,20 @@ def get_nav_title(cls) -> str:
167167
if cls.title:
168168
return cls.title
169169

170-
return cls.model._meta.model_name.capitalize()
170+
return cls.model.model_options.model_name.capitalize()
171171

172172
@classmethod
173173
def get_path(cls) -> str:
174174
if path := super().get_path():
175175
return path
176176

177-
return f"{cls.model._meta.model_name}/<int:id>/"
177+
return f"{cls.model.model_options.model_name}/<int:id>/"
178178

179179
def get_fields(self) -> list[str]:
180180
if fields := super().get_fields():
181181
return fields
182182

183-
return [f.name for f in self.object._meta.get_fields() if f.concrete]
183+
return [f.name for f in self.object._model_meta.get_fields() if f.concrete]
184184

185185
def get_field_value(self, obj: Any, field: str) -> Any:
186186
try:
@@ -204,14 +204,14 @@ def get_title(self) -> str:
204204
if title := super().get_title():
205205
return title
206206

207-
return f"New {self.model._meta.model_name}"
207+
return f"New {self.model.model_options.model_name}"
208208

209209
@classmethod
210210
def get_path(cls) -> str:
211211
if path := super().get_path():
212212
return path
213213

214-
return f"{cls.model._meta.model_name}/create/"
214+
return f"{cls.model.model_options.model_name}/create/"
215215

216216

217217
class AdminModelUpdateView(AdminUpdateView):
@@ -230,7 +230,7 @@ def get_path(cls) -> str:
230230
if path := super().get_path():
231231
return path
232232

233-
return f"{cls.model._meta.model_name}/<int:id>/update/"
233+
return f"{cls.model.model_options.model_name}/<int:id>/update/"
234234

235235
def get_object(self) -> models.Model:
236236
return self.model.query.get(id=self.url_kwargs["id"])
@@ -247,7 +247,7 @@ def get_path(cls) -> str:
247247
if path := super().get_path():
248248
return path
249249

250-
return f"{cls.model._meta.model_name}/<int:id>/delete/"
250+
return f"{cls.model.model_options.model_name}/<int:id>/delete/"
251251

252252
def get_object(self) -> models.Model:
253253
return self.model.query.get(id=self.url_kwargs["id"])

plain-api/plain/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class User(models.Model):
221221
required=False,
222222
)
223223

224-
_meta = models.Options(
224+
model_options = models.Options(
225225
constraints=[
226226
models.UniqueConstraint(
227227
fields=["api_key"],

plain-api/plain/api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class APIKey(models.Model):
2323

2424
api_version = models.CharField(max_length=255, required=False)
2525

26-
_meta = models.Options(
26+
model_options = models.Options(
2727
constraints=[
2828
models.UniqueConstraint(
2929
fields=["uuid"], name="plainapi_apikey_unique_uuid"

plain-cache/plain/cache/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CachedItem(models.Model):
2727

2828
query = CachedItemQuerySet()
2929

30-
_meta = models.Options(
30+
model_options = models.Options(
3131
indexes=[
3232
models.Index(fields=["expires_at"]),
3333
],

plain-flags/plain/flags/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FlagResult(models.Model):
2323
key = models.CharField(max_length=255)
2424
value = models.JSONField()
2525

26-
_meta = models.Options(
26+
model_options = models.Options(
2727
constraints=[
2828
models.UniqueConstraint(
2929
fields=["flag", "key"], name="plainflags_flagresult_unique_key"
@@ -51,7 +51,7 @@ class Flag(models.Model):
5151
# To provide an easier way to see if a flag is still being used
5252
used_at = models.DateTimeField(required=False, allow_null=True)
5353

54-
_meta = models.Options(
54+
model_options = models.Options(
5555
constraints=[
5656
models.UniqueConstraint(
5757
fields=["name"], name="plainflags_flag_unique_name"

plain-flags/plain/flags/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def coerce_key(key: Any) -> str:
1212
return key
1313

1414
if isinstance(key, models.Model):
15-
return f"{key._meta.package_label}.{key._meta.model_name}:{key.id}"
15+
return (
16+
f"{key.model_options.package_label}.{key.model_options.model_name}:{key.id}"
17+
)
1618

1719
return str(key)

plain-models/plain/models/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class User(models.Model):
200200
username = models.CharField(max_length=150)
201201
age = models.IntegerField()
202202

203-
_meta = models.Options(
203+
model_options = models.Options(
204204
indexes=[
205205
models.Index(fields=["email"]),
206206
models.Index(fields=["-created_at"], name="user_created_idx"),

plain-models/plain/models/backends/base/creation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def set_as_test_mirror(self, primary_settings_dict: dict[str, Any]) -> None:
9898
# and package_config.package_label in loader.migrated_packages
9999
# ):
100100
# for model in package_config.get_models():
101-
# if model._meta.can_migrate(
101+
# if model.model_options.can_migrate(
102102
# self.connection
103103
# ) and router.allow_migrate_model(self.connection.alias, model):
104104
# queryset = model._base_manager.using(
@@ -127,7 +127,7 @@ def set_as_test_mirror(self, primary_settings_dict: dict[str, Any]) -> None:
127127
# "json", data, using=self.connection.alias
128128
# ):
129129
# obj.save()
130-
# table_names.add(obj.object.__class__._meta.db_table)
130+
# table_names.add(obj.object.model_options.db_table)
131131
# # Manually check for any invalid keys that might have been added,
132132
# # because constraint checks were disabled.
133133
# self.connection.check_constraints(table_names=table_names)

plain-models/plain/models/backends/base/introspection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_migratable_models(self) -> Generator[Any, None, None]:
9494
for model in models_registry.get_models(
9595
package_label=package_config.package_label
9696
)
97-
if model._meta.can_migrate(self.connection)
97+
if model.model_options.can_migrate(self.connection)
9898
)
9999

100100
def plain_table_names(
@@ -108,8 +108,10 @@ def plain_table_names(
108108
"""
109109
tables = set()
110110
for model in self.get_migratable_models():
111-
tables.add(model._meta.db_table)
112-
tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many)
111+
tables.add(model.model_options.db_table)
112+
tables.update(
113+
f.m2m_db_table() for f in model._model_meta.local_many_to_many
114+
)
113115
tables = list(tables)
114116
if only_existing:
115117
existing_tables = set(self.table_names(include_views=include_views))
@@ -128,7 +130,9 @@ def sequence_list(self) -> list[dict[str, Any]]:
128130
for model in self.get_migratable_models():
129131
sequence_list.extend(
130132
self.get_sequences(
131-
cursor, model._meta.db_table, model._meta.local_fields
133+
cursor,
134+
model.model_options.db_table,
135+
model._model_meta.local_fields,
132136
)
133137
)
134138
return sequence_list

0 commit comments

Comments
 (0)