@@ -133,9 +133,7 @@ def offset(self, offset: int) -> QuerySet[MODEL]:
133133 """
134134 return self ._query .offset (offset )
135135
136- async def create (
137- self , using_db : BaseDBAsyncClient | None = None , ** kwargs : Any
138- ) -> MODEL :
136+ async def create (self , using_db : BaseDBAsyncClient | None = None , ** kwargs : Any ) -> MODEL :
139137 """
140138 Create a related record in the DB and returns the object, automatically setting the
141139 foreign key relationship to the parent instance.
@@ -167,9 +165,7 @@ async def create(
167165 # Call remote model's create method
168166 return await self .remote_model .create (using_db = using_db , ** kwargs )
169167
170- def _set_result_for_query (
171- self , sequence : list [MODEL ], attr : str | None = None
172- ) -> None :
168+ def _set_result_for_query (self , sequence : list [MODEL ], attr : str | None = None ) -> None :
173169 self ._fetched = True
174170 self .related_objects = sequence
175171 if attr :
@@ -187,18 +183,12 @@ class ManyToManyRelation(ReverseRelation[MODEL]):
187183 Many-to-many relation container for :func:`.ManyToManyField`.
188184 """
189185
190- def __init__ (
191- self , instance : Model , m2m_field : ManyToManyFieldInstance [MODEL ]
192- ) -> None :
193- super ().__init__ (
194- m2m_field .related_model , m2m_field .related_name , instance , "pk"
195- )
186+ def __init__ (self , instance : Model , m2m_field : ManyToManyFieldInstance [MODEL ]) -> None :
187+ super ().__init__ (m2m_field .related_model , m2m_field .related_name , instance , "pk" )
196188 self .field = m2m_field
197189 self .instance = instance
198190
199- async def add (
200- self , * instances : MODEL , using_db : BaseDBAsyncClient | None = None
201- ) -> None :
191+ async def add (self , * instances : MODEL , using_db : BaseDBAsyncClient | None = None ) -> None :
202192 """
203193 Adds one or more of ``instances`` to the relation.
204194
@@ -217,9 +207,7 @@ async def add(
217207 pks_f : list = []
218208 for instance_to_add in instances :
219209 if not instance_to_add ._saved_in_db :
220- raise OperationalError (
221- f"You should first call .save() on { instance_to_add } "
222- )
210+ raise OperationalError (f"You should first call .save() on { instance_to_add } " )
223211 pk_f = related_pk_formatting_func (instance_to_add .pk , instance_to_add )
224212 pks_f .append (pk_f )
225213 through_table = Table (self .field .through , schema = self .field .through_schema )
@@ -229,13 +217,9 @@ async def add(
229217 through_table [forward_key ],
230218 )
231219 select_query = (
232- db .query_class .from_ (through_table )
233- .where (backward_field == pk_b )
234- .select (forward_key )
235- )
236- criterion = (
237- forward_field == pks_f [0 ] if len (pks_f ) == 1 else forward_field .isin (pks_f )
220+ db .query_class .from_ (through_table ).where (backward_field == pk_b ).select (forward_key )
238221 )
222+ criterion = forward_field == pks_f [0 ] if len (pks_f ) == 1 else forward_field .isin (pks_f )
239223 select_query = select_query .where (criterion )
240224
241225 _ , already_existing_relations_raw = await db .execute_query (
@@ -247,9 +231,7 @@ async def add(
247231 }
248232
249233 if pks_f_to_insert := set (pks_f ) - already_existing_forward_pks :
250- query = db .query_class .into (through_table ).columns (
251- forward_field , backward_field
252- )
234+ query = db .query_class .into (through_table ).columns (forward_field , backward_field )
253235 for pk_f in pks_f_to_insert :
254236 query = query .insert (pk_f , pk_b )
255237 await db .execute_query (* query .get_parameterized_sql ())
@@ -260,9 +242,7 @@ async def clear(self, using_db: BaseDBAsyncClient | None = None) -> None:
260242 """
261243 await self ._remove_or_clear (using_db = using_db )
262244
263- async def remove (
264- self , * instances : MODEL , using_db : BaseDBAsyncClient | None = None
265- ) -> None :
245+ async def remove (self , * instances : MODEL , using_db : BaseDBAsyncClient | None = None ) -> None :
266246 """
267247 Removes one or more of ``instances`` from the relation.
268248
@@ -287,9 +267,9 @@ async def _remove_or_clear(
287267 if instances :
288268 related_pk_formatting_func = type (instances [0 ])._meta .pk .to_db_value
289269 if len (instances ) == 1 :
290- condition &= through_table [
291- self . field . forward_key
292- ] == related_pk_formatting_func ( instances [ 0 ]. pk , instances [ 0 ] )
270+ condition &= through_table [self . field . forward_key ] == related_pk_formatting_func (
271+ instances [ 0 ]. pk , instances [ 0 ]
272+ )
293273 else :
294274 condition &= through_table [self .field .forward_key ].isin (
295275 [related_pk_formatting_func (i .pk , i ) for i in instances ]
@@ -317,9 +297,7 @@ def __init__(
317297 if TYPE_CHECKING :
318298
319299 @overload
320- def __get__ (
321- self , instance : None , owner : type [Model ]
322- ) -> RelationalField [MODEL ]: ...
300+ def __get__ (self , instance : None , owner : type [Model ]) -> RelationalField [MODEL ]: ...
323301
324302 @overload
325303 def __get__ (self , instance : Model , owner : type [Model ]) -> MODEL : ...
@@ -348,9 +326,7 @@ def validate_model_name(cls, model_name: str | type[Model]) -> None:
348326 ) from None
349327 elif len (model_name .split ("." )) != 2 :
350328 field_type = cls .__name__ .replace ("Instance" , "" )
351- raise ConfigurationError (
352- f'{ field_type } accepts model name in format "app.Model"'
353- )
329+ raise ConfigurationError (f'{ field_type } accepts model name in format "app.Model"' )
354330
355331
356332class ForeignKeyFieldInstance (RelationalField [MODEL ]):
@@ -370,9 +346,7 @@ def __init__(
370346 "on_delete can only be CASCADE, RESTRICT, SET_NULL, SET_DEFAULT or NO_ACTION"
371347 )
372348 if on_delete == SET_NULL and not bool (kwargs .get ("null" )):
373- raise ConfigurationError (
374- "If on_delete is SET_NULL, then field must have null=True set"
375- )
349+ raise ConfigurationError ("If on_delete is SET_NULL, then field must have null=True set" )
376350 self .on_delete = on_delete
377351
378352 def describe (self , serializable : bool ) -> dict :
0 commit comments