SCGR commited on
Commit
51080e6
·
1 Parent(s): 8c3c8d3

admin delete

Browse files
py_backend/app/crud.py CHANGED
@@ -242,17 +242,14 @@ def update_model(db: Session, m_code: str, update_data: dict):
242
  return model
243
 
244
  def delete_model(db: Session, m_code: str):
245
- """Soft delete a model by incrementing delete count and marking as unavailable"""
246
  model = db.get(models.Models, m_code)
247
  if not model:
248
  return False
249
 
250
- # Increment delete count and mark as unavailable
251
- model.delete_count += 1
252
- model.is_available = False
253
-
254
  db.commit()
255
- db.refresh(model)
256
  return True
257
 
258
  def get_all_schemas(db: Session):
 
242
  return model
243
 
244
  def delete_model(db: Session, m_code: str):
245
+ """Hard delete a model by removing it from the database"""
246
  model = db.get(models.Models, m_code)
247
  if not model:
248
  return False
249
 
250
+ # Remove the model from the database
251
+ db.delete(model)
 
 
252
  db.commit()
 
253
  return True
254
 
255
  def get_all_schemas(db: Session):
py_backend/app/routers/admin.py CHANGED
@@ -299,11 +299,11 @@ async def delete_model(
299
  detail=f"Cannot delete model '{model_code}' - it is used by {image_count} image(s)"
300
  )
301
 
302
- # Soft delete model (increment delete count and mark as unavailable)
303
  crud.delete_model(db, model_code)
304
 
305
  return {
306
- "message": f"Model '{model_code}' soft deleted successfully (delete count incremented)"
307
  }
308
  except Exception as e:
309
  raise HTTPException(
 
299
  detail=f"Cannot delete model '{model_code}' - it is used by {image_count} image(s)"
300
  )
301
 
302
+ # Hard delete model (remove from database)
303
  crud.delete_model(db, model_code)
304
 
305
  return {
306
+ "message": f"Model '{model_code}' deleted successfully from database"
307
  }
308
  except Exception as e:
309
  raise HTTPException(